Replies: 2 comments 1 reply
-
hi @sylqiu It will be great to understand your use case better. Uploady's sender works well for http end-points. There is a great ability for flexibility and configuration even at run-time and at the batch/request level. If you need to pass the upload not to a http request but to another API (ex: 3rd party SDK) then this discussion will be useful. It sounds like you're asking about the same thing. Providing a custom send method (using Uploady's props) is your best approach. |
Beta Was this translation helpful? Give feedback.
-
Amazing! Thanks for your pointer, I am able to achieve the purpose by something like the following: import { ref, uploadBytes, StorageReference, getStorage } from "firebase/storage";
import { BatchItem, FILE_STATES, UploadData } from "@rpldy/shared";
import { OnProgress, SendMethod, SendOptions, SendResult } from "@rpldy/sender";
const storage = getStorage()
const getRequestData = (items: BatchItem[]) => {
if (items.length > 1) {
throw new Error(
`Firebase storage accepts only single file upload,
while ${items.length} received.`
);
}
if (items.length == 0) {
throw new Error("No upload items found.");
}
console.log(items[0])
return items[0].file;
};
const sendRequest = (
storageRef: StorageReference,
items: BatchItem[]
): Promise<UploadData> =>
uploadBytes(storageRef, <Blob>(<unknown>getRequestData(items)))
.then((snapshot) => {
console.log("upload successful")
return {
status: 1,
state: FILE_STATES.FINISHED,
response: null,
};
})
.catch((error) => {
console.log("upload failed")
return {
status: 0,
state: FILE_STATES.ERROR,
response: error,
};
});
export const sender: SendMethod = (
items: BatchItem[],
url: string | undefined,
options: SendOptions,
onProgress?: OnProgress
): SendResult => {
console.log(url)
const storageRef = ref(storage, url);
return {
request: sendRequest(storageRef, items),
abort: () => false,
senderType: "FIREBASE_CLOUD_STORAGE",
};
}; The |
Beta Was this translation helpful? Give feedback.
-
I am trying to find how to upload with a service API such as firebase cloud storage instead of the destination URL.
Is it possible currently? If would be really nice to be able to configure the sender.
Beta Was this translation helpful? Give feedback.
All reactions