joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 784 forks source link

POST call keeps the file in queue #769

Open the-easy-developer opened 2 years ago

the-easy-developer commented 2 years ago

Hello, I am using this package in my project. It is used at 2 different places. At 1 of the place, it works like a charm probably because the API call uses GET method. At the second place where I am using this package, the API supports POST method. It is here that the code is not working. I have brainstormed a lot in the past 4 days but have not been able to find a solution. Below is the code snippet of RNFetchBlob :

const path = RNFetchBlob.fs.dirs.DownloadDir + '/' + fileName // fileName is reports.csv
RNFetchBlob.config({
      addAndroidDownloads: {
        useDownloadManager: true,
        notification: true,
        title: 'Download reports.csv',
        description: '',
        mime: 'text/csv',
        mediaScannable: true,
        path,
      },
    })
    .fetch(
        'POST',
        "https://this-is-the-url.com",
        {
                  'Content-Type': 'application/json',
                  Authorization: "Bearer <token>",
        },
        [{ name: "some-name", data: "some-string" }]    
    )
    .progress((received, total) => {
      console.log(received, total)
    })
    .then(r => {
      console.log('R', r)
    })
    .catch((e) => {
      console.log('ERROR', e)
    })

If someone can help me out, it'd be great. I have a hunch that I am messing up somewhere with the request body. I have tried sending request bodies in different ways, as plain JavaScript object, before sending encoding the object using RNFetchBlob.base64.encode, finally I found in the docs about using array of object and each object has name and data keys, but this is also not working.

One thing that I noticed is when I delete the file from the downloads folder where it shows me "queued" below the filename, it triggers the then part of fetch.