numandev1 / react-native-compressor

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

upload formData instead of fileUri #242

Open segun-flexible opened 1 year ago

segun-flexible commented 1 year 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 1 year 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 1 year ago

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

github-actions[bot] commented 5 days ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.