Upload function is not working for createUploader object from @rpldy/uploader package
bhanu-atwork opened this issue · 3 comments
I am trying to upload a file in a monorepo which in typescript. My expectations are if I have File object, it should upload file to a particular destination. I used @rpldy/uploady package for web and react-native-document-picker package for mobile to capture file object. As per my understanding @rpldy/uploader package can help me to upload corresponding file. I can use simple multiple part upload but this package provides me functionality to cancel, monitor progress of upload and many things in a simpler way.
I tried to imitate the implementation in my react-native package but its not working.
const uploader = createUploader({ destination: { url: 'https://my-server.com/upload' }, autoUpload: false });
uploader.add([file], { autoUpload: false });
uploader.on(UPLOADER_EVENTS.BATCH_ADD, (batch) => {
console.log(`NEW BATCH ADDED WITH ${batch.items.length} FILES`, batch);
});
uploader.on(UPLOADER_EVENTS.BATCH_START, (batch) => {
console.log(`NEW BATCH STARTED WITH ${batch.items.length} FILES`, batch);
});
uploader.on(UPLOADER_EVENTS.BATCH_FINISH, (batch) => {
console.log(`NEW BATCH FINISH WITH ${batch.items.length} FILES`, batch);
});
uploader.upload();
In console only UPLOADER_EVENTS.BATCH_ADD is getting logged out. No other events are coming. I tried to shuffle destination and auto-upload as false in all 3 three place of createUploader, add function and upload function Can anyone please let me know what I am doing wrong.
Hi @bhanu-atwork
It's strange that you're having problems as the Events mechanism inside Uploady has been extremely stable.
I created a new sandbox to test it and Im seeing all events being registered:
For me to be able to assist further, please provide a reproducing code/sandbox that I can run.
Thanks @yoavniran for the explanation. It is working now. But whenever I am picking file from document picker it is giving "Failed to execute 'set' on 'FormData': parameter 2 is not of type 'Blob'.". Can we use createUploader instance to directly upload file without changing source URI to File object ? Thank you for the help.
Its unclear to me what youre trying to upload but -
You can upload strings instead of a File/Blob object. That's what the upload-url-input component does.
You can also just send the data (string,object, etc.) directly by setting the sendWithFormData (see upload options) to false.
(converting to a discussion)