I would like download file on React-Native app. The problem is not about React-Native, but i don't know how i can download the xlsx file using post request. when i go to download its show status code 16

const token = await AsyncStorage.getItem('accessToken');
      const {config, fs} = RNFetchBlob;
      let DOCUMENT_DIR = fs?.dirs?.DownloadDir;

      let date = new Date();
      let options = {
        fileCache: true,
        trusty: true,
        addAndroidDownloads: {
          useDownloadManager: true,
          notification: true,
          title: 'Downloading....',
          path:
            DOCUMENT_DIR +
            '/Download' +
            Math.floor(date.getTime() + date.getSeconds() / 2) +
            '.xlsx',
          description: 'Downloading..',
        },
      };

      const response = await config(options).fetch(
        'POST',
        `${BASE_URL}/auth/bulk-export`,
        {
          'Content-Type': 'application/octet-stream',
          Authorization: `Bearer ${token}`,
        },
        JSON.stringify(myData),
      );

      const status = response.info().status;

      if (status === 200) {
        Toast.show({
          title: 'Success',
          description: 'File downloaded successfully',
          bgColor: COLORS.secondary,
        });
      } else {
        console.error('Failed to download file. Status:', status);
      }
    } catch (error) {
      console.error('Error during file download:', error);
    }

I am using Rn-fetch-bolb to download using post request but error status code 16, Anyone have already download file using post request or any one have solution?

0

There are 0 best solutions below