4

I need to upload big file on server using rn-fetch-blob in react native. The problem is when file size is more than ~10MB, App crashes without error message. File path comes from react-native-share-extension. Platform - iOS. On Android and iOS simulator everything works fine.

const uploadUri = Platform.OS === 'ios' ? value.replace('file://', '') : value;

const headers = {
   'Content-Type': 'multipart/form-data',
   Accept: 'application/json',
};

const jsonData = [
      {
        name: 'title',
        data: title,
      },
      {
        name: 'file',
        filename: `${Math.random()
          .toString(36)
          .substr(2, 9)}-${new Date().getTime()}.${extension}`,
        type: filetype,
        data: RNFetchBlob.wrap(uploadUri),
      },
    ];

RNFetchBlob.fetch('POST', url, headers, jsonData)
   .then(res => {
      console.log('uploaded')
   })
   .catch(err => {
      console.log('error');
   }); 

I've tried using readStream and it also didn't help

RNFetchBlob.fs
  .readStream(
    uploadUri,
    'base64',
    4095,
    100
  )
  .then(ifstream => {
    ifstream.open();
    ifstream.onData(chunk => {
      data += chunk
    });

    ifstream.onEnd(() => {
      console.log('end');
    });
  });
Juergen Schulze
  • 1,515
  • 21
  • 29

0 Answers0