numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
831 stars 84 forks source link

upload formData instead of fileUri #242

Open segun-flexible opened 8 months ago

segun-flexible commented 8 months ago

am requesting if there is a way take advantage of the background upload, instead of upload passing fileUri, we can just pass in formData which we have append all data we want to send to the backend.

am currently using axios, but there is no way i can leverage the backrgound upload const result = await axios({ url: "/api/user/post", method: "POST", data: formData, headers: { 'Content-Type': 'multipart/form-data' } }, onUploadProgress);

const uploadResult = await backgroundUpload( url, fileUrl, { uploadType: UploadType.MULTIPART, httpMethod: 'POST', headers }, (written, total) => { console.log(written, total); } );

ursnj commented 8 months ago

You can submit form data something like this :

export const uploadBackground = async (url: string, file: string, data: any) => {
  return backgroundUpload(CONFIG.API_URL + url, file, {
    uploadType: UploadType.MULTIPART,
    httpMethod: UploaderHttpMethod.POST,
    fieldName: 'myFile',
    mimeType: getMimeType(file),
    parameters: data, // This is nothing but your other data apart from image
    headers: {
      Authorization: 'Bearer ' + Storage.get('TOKEN')
    }
  });
};
johnrevs commented 7 months ago

Is there any way to upload multiple files (videos and images)? Along with data as parameters