react-native-fetch-blob icon indicating copy to clipboard operation
react-native-fetch-blob copied to clipboard

Process file:// URIs on iOS.

Open ivankashtanov opened this issue 7 years ago • 6 comments

Hi, I've been using this package in conjunction with react-native-document-picker to select and upload files from iOS device.

Picker package opens standard iOS file picker which returns URI like file:///private/var... as result. When I pass such URI in parameters for fetch function using wrap helper, it reports that selected file doesn't exist. The issue is that here this URI is treated as a simple path and file existence request returns NO.

If I strip file:// part before calling wrap, it works as expected

Is it possible to add handling for file URIs there so that there's no need of additional preparations? Or is there an additional setting that should be used in this case?

Versions: RN 0.42.3, RNFB 0.10.5

ivankashtanov avatar Jun 05 '17 15:06 ivankashtanov

I have same problem

abdurrahmanekr avatar Jul 13 '17 08:07 abdurrahmanekr

Same issue, any news on this?

isAlmogK avatar Aug 07 '17 08:08 isAlmogK

Is this really an issue?

If I strip file:// part before calling wrap, it works as expected

The documentation says a "path" is expected, and doing so seems simple enough. Sure code could be added to RNFB stripping file://, but the app's code can do it just as easily.

lll000111 avatar Sep 07 '17 09:09 lll000111

I'm facing the same issue but the suggestions above didn't help.

I'm using react-native-document-picker as well as this RNFetchBlob and it seems to work fine for images and PDF files, but when I pick any other document (.docx, .pages, etc..) I always get RNFetchBlob.fetchBlobForm failed to create request body

This is the code that handles the upload. Is there anything I'm missing?

      // Removes unwanted start of fileDir string
      const cleanFilePath = fileDir.replace('file://', '');
      const body = [
        {
          name: 'entity_document',
          data: JSON.stringify(docProps),
          type: 'application/json'
        },
        {
          name: 'VersionData',
          filename: fileName,
          data: RNFetchBlob.wrap(cleanFilePath),
          type: fileType
        }
      ];
     RNFetchBlob.fetch(
        'POST',
        `${instanceUrl}/services/data/v40.0/sobjects/ContentVersion`,
        {
          Authorization: `Bearer ${accessToken}`,
          'Content-Type': 'multipart/form-data'
        },
        body
      )
        .then(res => {
          ...
        });

CarlosJJR avatar Aug 15 '18 21:08 CarlosJJR

created a PR in the fork: https://github.com/joltup/rn-fetch-blob/pull/211

Jyrno42 avatar Oct 17 '18 08:10 Jyrno42

I'm facing the same issue but the suggestions above didn't help.

I'm using react-native-document-picker as well as this RNFetchBlob and it seems to work fine for images and PDF files, but when I pick any other document (.docx, .pages, etc..) I always get RNFetchBlob.fetchBlobForm failed to create request body

This is the code that handles the upload. Is there anything I'm missing?

      // Removes unwanted start of fileDir string
      const cleanFilePath = fileDir.replace('file://', '');
      const body = [
        {
          name: 'entity_document',
          data: JSON.stringify(docProps),
          type: 'application/json'
        },
        {
          name: 'VersionData',
          filename: fileName,
          data: RNFetchBlob.wrap(cleanFilePath),
          type: fileType
        }
      ];
     RNFetchBlob.fetch(
        'POST',
        `${instanceUrl}/services/data/v40.0/sobjects/ContentVersion`,
        {
          Authorization: `Bearer ${accessToken}`,
          'Content-Type': 'multipart/form-data'
        },
        body
      )
        .then(res => {
          ...
        });

How you solved it?

diaraujo13 avatar Nov 23 '18 23:11 diaraujo13