我正在使用包含 axios 的 React-query 来获取 API,并尝试将响应保存/下载到 Excel 文件并存储它。下面是代码和 api 响应。我无法确定是否遗漏了任何标头、响应类型是否不正确或 RNFS.writeFile 调用是否错误。
\nimport axios from 'axios';\nimport RNFS from 'react-native-fs';\nimport {useQuery} from 'react-query';\n\nexport function useExportGains(\n accountId: number,\n fileFormat: string,\n fromDate: string,\n toDate: string,\n) {\n const getReport = async () => {\n const baseApiUrl = 'https://devenv.product.com/API'; // api url\n const Api = axios.create({baseURL: baseApiUrl});\n const params = {\n fromDate: fromDate,\n toDate: toDate,\n contextFilter: {\n appUserIds: [1],\n },\n };\n\n const mimeType =\n fileFormat === 'pdf'\n ? 'application/pdf'\n : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n\n Api.get(`Reporting/AccountAnalytics/${accountId}/exportGains/${fileFormat}`, {\n params,\n …Run Code Online (Sandbox Code Playgroud)