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

Downloading excel file from server response give incorrect xlsx #730

Open avtarvikas opened 3 years ago

avtarvikas commented 3 years ago
const exportAttendanceReport = payload => async dispatch => {
  try {
    const { data } = await axios.post(
      "user/attendance/report/export",
      {
        ...payload
      },
      {
        responseType: "blob"
      }
    );

    const pathToWrite = `${
      RNFetchBlob.fs.dirs.DownloadDir
    }/Attendance-Report-${moment(payload.yearMonth, "YYYY-MM").format(
      "MMM"
    )}.xlsx`;
    RNFetchBlob.fs
      .writeFile(pathToWrite, RNFetchBlob.base64.encode(data), "base64")
      .then(() => {
        showMessage(
          "Excel File Downloaded Successfully !!",
          "file has been saved to download folder"
        );
        NavigationService.goBack();
      })
      .catch(error => showError("Failed to read file", error));
  } catch (err) {
    showError("Failed to download file", err);
  }
};

"rn-fetch-blob": "^0.12.0"

File is getting downloaded but when i open it it shows [object][object]

saurabhkanswal commented 1 year ago

@avtarvikas do you find any solution ?

avtarvikas commented 1 year ago

@saurabhkanswal I left that project ;-)