RN-fetch-blob无法下载文件始终失败

时间:2020-05-07 15:13:58

标签: react-native file

Im working on react native fetch blob to download the file. The file basically are in my nodejs server.
I have tried to get it from post man and its successfully working. But when i attached the api into rn-fetch-blob it shows me download failed even file exists. I have checked 10 time my installation is correct there is no issue there. Can any body help me to get out of this.

所以这是我的节点api router.post('/ download-proof',documents.proofDownload);

proofDownload:(req,res)=> { 让filepath = path.join(__ dirname,'.. / .. / .. / documents /')+ req.body.filename res.setHeader('Content-Disposition','attachment; filename ='+ req.body.filename); res.setHeader('Content-Transfer-Encoding','binary'); res.setHeader('Content-Type',req.body.mimetype); res.download(文件路径)

}, 

在邮递员中工作正常

这是rn-fetch-blob

let options = {
             fileCache: true,
             appendExt: getExt,
             addAndroidDownloads: {
                 useDownloadManager: true, // setting it to true will use the device's native download manager and will be shown in the notification bar.
           notification: true,
           description: 'Downloading file.',

           path:
              pathToDir +
              `/${file.filename}` ,
         },
         path:
         pathToDir +
           `/${file.filename}` ,

           notification: true,
       };

       console.log(file," docs")
       console.log(options.path, pathToDir,"options")
     let body = {
         filename: file.filename,
         mimetype: file.mimetype
     }
      console.log(body, "line no 62")
     let url = `http://3.21.33.146:3000/download-proof`;
     console.log(url);
      config(options)
     .fetch("POST", url,{}, JSON.stringify(body))
     .progress({interval: 250}, (received, total) => {})
     .then((res) => {
              console.log(res, "fetch blob response")

             }).catch((err) => {
             console.log(err)
          })

         } else {
         Alert.alert(
             "Permission Denied!",
             "You need to give storage permission to download the file"
         );
         }
     } catch (err) {
         console.log(err);
     }
     }

它给我状态码16错误,不知道是什么问题。

0 个答案:

没有答案