用于下载文件调用的离子cordova无效标头

问题描述

我正在尝试使用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" 选项需要是一个字典样式的对象, 即使我的标题是 {[key: string],string | 所需的格式string[]} 因为每个键都是一个字符串,每个值都是一个字符串。

使用 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...