question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to fetch when file has spaces in name.

See original GitHub issue

Hello!

When I try to upload a file that has a space in its name (like “FILE A”), I get this error.

Failed to create form data from content URI:content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2FFILE A.docx, Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider uri content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2FFILE A.docx from pid=28475, uid=10155 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

image

code:

await RNFetchBlob.fetch('POST', url, {
        token: 'token',
    }, [
        {
            name: 'file0',
            filename: file.name,
            data: RNFetchBlob.wrap(decodeURI(fileURI)),
        },
    ]);

If you remove the space from the name, everything works fine.

env platform: Android react-native: “0.62.2”, rn-fetch-blob: “^0.12.0” minSdkVersion = 23 compileSdkVersion = 28 targetSdkVersion = 28

p.s: RNFB.fs.exist(uri) returns true p.p.s:“FILE_A” for example uploads fine.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
cpecoraricommented, Sep 22, 2020

Hi, had the problem too, solved it like this as path is not interpreted the same way in iOS and Android :

filename: file.name.replace(/\s/g, '_'),
name: 'files[]',
data:
        Platform.OS === 'ios'
          ? 'RNFetchBlob-' + decodeURI(file.uri)
          : RNFetchBlob.wrap(file.uri.replace(/file:\/\//g, ''))
0reactions
AireshBhatcommented, Feb 23, 2021

Encode the URI as well as shown below:

await RNFetchBlob.fetch('POST', encodeURI(url), {
        token: 'token',
    }, [
        {
            name: 'file0',
            filename: file.name,
            data: RNFetchBlob.wrap(decodeURI(fileURI)),
        },
    ]);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem: Having file name contain Space and fetch the file
Closed 6 years ago. I am trying to get all file which is reside in one folder and file name have space like...
Read more >
If the path of a file has space in between the uri cannot ...
In Java: URI uri = new File("spaces in file name").toURI();.
Read more >
FetchGCSObject processor in NiFi fails to fetch files with ...
I am running into a problem with the NiFi fetchgcsobject processor.. It fails when trying to retrieve files with spaces in the file...
Read more >
[Help] Cannot download file if the file name has spaces
when i use download API, it works well if download FileName does not has space. But return eroor 400 if download FileName has...
Read more >
How to Read a Filename with Spaces in Linux
If you want to view such a file with space in the file name, use the same principle of enclosing the file names...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found