rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

[Error: document is not supported] cannot open .xlsx document on iOS.

Open MannySauce opened this issue 4 years ago • 6 comments

Im fetching an excel file generated by server, then gives the user the option to open it after its downloaded.. it works perfectly fine on android, but on iOS it only downloads the file to the File App I can then open it in there, but we would like for it to open from app. I stripped some of the android code out and tried it again but it still gives the problem. I have also added the 2 necessary keys in info.plist, and did the pod thing.. any help is appreciated thanks

<key> UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
handleDownloadPress = async () => {
    this.setState({isDownloading: true, optionsVisible: false});
    const {startDate, endDate} = this.state;
    let dirs = RNFetchBlob.fs.dirs;
const android = RNFetchBlob.android;
const filename = `Reporte${startDate}-${endDate}.xlsx`;
const platPath = Platform.OS === "android" ? dirs.DownloadDir : dirs.DocumentDir;
const path = platPath + '/' + filename;

RNFetchBlob.config({
  addAndroidDownloads: {
    useDownloadManager: true,
    path,
    notification: true,
  },
  path,
  fileCache: true
})
  .fetch(
    'GET',
    `${BASE_URL}rest/pedidos/generateExcel?initDate=${startDate}&endDate=${endDate}T23:59:59`,
    {
      token: this.props.session.access_token,
      idrest: this.props.session.info_rest.id,
    },
  )
  .then((res) => {
    //shows a modal with a button 
    this.alertConfig.onBtnPress = ()=>{
      if(Platform.OS === "android"){
        android.actionViewIntent(res.path(), 'application/vnd.ms-excel');
      }
      else {
        RNFetchBlob.ios.openDocument(res.path());
      }
    }
    this.setState({isDownloading: false, isAlertVisible: true});//show modal
  })
  .catch((errorMessage, statusCode) => {
   //printStatements, toggleing states
  });

};

MannySauce avatar Sep 15 '20 23:09 MannySauce

I have same issue,

On a physical device (iPhone 11 - iOS 13.5) When I try to execute openDocument or previewDocument both fails and crashes the app without giving any error in the debug console. Then I tried with the catch block and the exception says the file not supported.

On the simulator, It opens up the document but doesn't show its contents image

dhananjaya90 avatar Nov 15 '20 11:11 dhananjaya90

@MannySAD @dhananjaya90 Did you find any way to work around this?

sunn-e avatar Jan 14 '21 12:01 sunn-e

@MannySAD @dhananjaya90 Did you find any way to work around this?

What I wanted to do initially was to download the file to the file app and if the user wanted to view it he would have to press a button I had inside an alert/modal, I investigated a bit and found out people were having the same problem (opening recent downloaded files on button press inside modal) so I switched to RNFetchBlob.ios.previewDocument(res.path()); (only for ios) now once the user presses the download button the native ios share menu pops up instead of the modal.. the user can then choose if he only wants to store it or store and open it through the excel app. But im thinking this is situational to what you want, I left it like this because I didnt find a solution to open it directly.

MannySauce avatar Jan 14 '21 16:01 MannySauce

@dhananjaya90 can u help me

linhkiubo98 avatar Oct 22 '21 10:10 linhkiubo98

this is my code ,on IOS crash app let dirs = RNFetchBlob.fs.dirs; const url = item.url; RNFetchBlob.config({ path: dirs.DocumentDir + url.slice(url.lastIndexOf('/'), url.length), addAndroidDownloads: { useDownloadManager: true, title: url.slice(url.lastIndexOf('/') + 1, url.length), mediaScannable: true, notification: true, path: dirs.DocumentDir + url.slice(url.lastIndexOf('/'), url.length), }, fileCache: true, }).fetch('GET', url).then((res) => { console.log(res.data, res.path());

    try {
      RNFetchBlob.ios.openDocument(res.path())  
    } catch (error) {
      console.log('xxxxxxxxxxx',error);
      
    }
  });

linhkiubo98 avatar Oct 22 '21 10:10 linhkiubo98

Guys Can somebody please help me with the same, for me everything is working on iPhone SE(3rd Generation), but not working on iPhone 14.

RN Version - 71.8 Rn-Fetch-Blob - 0.12.0

  • I am able to Preview the file and download the file on iPhone SE(3rd Generation) - Simulator
  • I am not able to do the same in iPhone 14

jyotiprakash111 avatar Jun 27 '23 12:06 jyotiprakash111