问题描述
我正在尝试使用cordova 的高级http 插件将excel 文件保存到我的iOS 设备。我的方法如下:
import { HTTP } from '@ionic-native/http/ngx';
import { File } from '@ionic-native/file/ngx';
public downloadFile(url: string,body: any): void {
const fileName: string = `${this.file.documentsDirectory}excel-test.xls`;
const headers: any = {
Content-Type: 'application/json',Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',X-CUSTOM-HEADER1: 'valueOne',X-CUSTOM-HEADER2: 'valueTwo',X-CUSTOM-HEADER3: 'valueThree',Authorization: 'Bearer token',X-authorization: 'Bearer token'
}
const response = await this.http.downloadFile(url,body,headers,fileName);
}
这导致:错误:advanced-http: "params" 选项需要是一个字典样式的对象,
使用 sendRequest 方法(如下),相同的标头集可以正常工作,但同样,我希望将文件下载到设备。
public sendRequest(url: string,method: string,responseType: string,data?: any): void {
const headers: any = {
Content-Type: 'application/json',X-authorization: 'Bearer token'
}
const options = {
method,// this is post
headers,responseType,// this is blob
data
}
const response = await this.http.sendRequest(url,options)
}
从文档来看,我看不出标题的使用有什么不同,也无法理解为什么它适用于 sendRequest 而不适用于 downloadFile。我怎样才能让我的标题与这个调用一起工作? (或者甚至如何在成功调用 sendRequest 后手动将文件保存到我的设备?)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)