Downloading PDF file in React Native for IOS using rn-fetch-blob

2.4k views Asked by At

I use this library (rn-fetch-blob) to download base64 pdf from the server. This is my code below:

RNFetchBlob.config({ 
      fileCache: true, 
      path: RNFetchBlob.fs.dirs.DocumentDir + "/" + this.getFileName(),
      
    }) 
      .fetch(
        "POST",
        api.downloadPDFFile,
        {
          Authorization: "Bearer " + this.state.token,
          "Content-Type": "application/json",
        },
        JSON.stringify(this.state.requestData)
      )

      .then((resp) => {
        if (Platform.OS === "ios") {
          RNFetchBlob.ios.previewDocument(resp.data);
        }
        let base64Str = resp.data;
        RNFetchBlob.fs.writeFile(path, base64Str, "base64"); 
       
      })
      .catch((err) => {
        this.hideProgress();
        console.log("Error", err);
      })
      .finally((onFinally) => {
        this.hideProgress();
        this.refs.DownloadModal.open();
      }).done;

I can download the pdf file on an android device with no issues, unfortunately, it fails in the case of IOS. I receive an error in the catch stating [Error: unsupported URL] Any Solution?

0

There are 0 answers