joltup / rn-fetch-blob

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

Download doesn't work or showing wrong progress #771

Open iphonic opened 2 years ago

iphonic commented 2 years ago

Hi, Using library version 0.12.0. Facing two issues, both with downloading, issues are

  1. Download doesn't work with internal redirection with some specific endpoint URL which have redirections
  2. Download works, but download progress is wrong, always receiving total - 1

Following is the code we trying, please point out mistake

var parameters={appver:"1",osver:"android",ver:"7",token:"sessiontoken"}

var headers={"X-API-KEY":apikey,"X-USER-KEY":userkey,"Accept": 'multipart/form-data' }

const dirs = RNFetchBlob.fs.dirs
const downloadpath=`${dirs.DocumentDir}/${filename}`

RNFetchBlob.config({
    path:downloadpath,
    fileCache:true,
})
.fetch('POST',url,{
    ...headers
},
JSON.stringify(parameters)
)
.progress((received,total)=>{

    console.log("received ",received);
    console.log("TOTAL ",total);     //  <=========== Receiving -1 always
    console.log('progress', received / total)

})
.then((res)=>{
    console.log(res);
})
.catch((err)=>{
    console.log(err);
})

Thanks for Help.

lucaslz2020 commented 2 years ago

same issues rn-fetch-blob: "0.13.0-beta-1"

ZexinW commented 1 year ago

total is -1, either because your url is incorrect or because the file isn't currently available.