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 771 forks source link

how to open a blob file #752

Open hanaechahid opened 2 years ago

hanaechahid commented 2 years ago

Hi! I have ana api that returns blob object and I want to open it in my react native project using another library react-native-file-viewer but I don't know how to get path from blob.

could anyone help me in this please?

My code is like this:

axios.get(url, {
            header,
            responseType: 'blob'
          })
          .then(async res => {
            let blob = res.data._data;
            console.log(blob);
            RNFetchBlob.config({
              fileCache: true,
              appendExt: step.MimeType.split("/")[1]
            })
              .fetch("GET", fileLocation) // don't know how can I get fileLocation value
              .then(res => {
                let path = res.path();
                console.log(path)
                FileViewer.open(path)
                .then(() => {
                  console.log("success")
                  this.setState({
                    modalVisible: false
                  });
                })
                .catch(error => {
                  this.setState({
                    modalVisible: false
                  });
                });
              })
              .catch((errorMessage, statusCode) => {
                console.log(errorMessage)
                this.setState({
                  modalVisible: false
                });
              });
          })
          .catch(err =>{
            console.log(err)
          })
retyui commented 2 years ago

Hi @hanaechahid This module is unmentionable ⚠️! please use fork: https://github.com/RonRadtke/react-native-blob-util