【问题标题】:angular file uploader methods for http requesthttp请求的角度文件上传器方法
【发布时间】:2022-01-01 21:09:38
【问题描述】:

我正在尝试使用 angular-file-uploader 并上传文件。 在 afuConfig 中,我想将方法​​设置为 POST 但在终端中出现错误。

uploadAPI:  {
      url:"https://example-file-upload-api",
      method:"POST",
      headers: {
     "Content-Type" : "text/plain;charset=UTF-8",
      },
}

它给了我这个:

  The types of 'uploadAPI.responseType' are incompatible between these types.
    Type 'string' is not assignable to type '"blob" | "json" | "arraybuffer" | "text" | undefined'.

我在使用 responseType 时也遇到了同样的问题。

【问题讨论】:

    标签: javascript angular file-upload


    【解决方案1】:

    默认responseTypejson。尝试明确分配responseType: text

    uploadAPI: {  
      url: "https://example-file-upload-api",
      method:"POST",
      headers: {
        "Content-Type" : "text/plain;charset=UTF-8",
      },
      responseType: 'text'
    }
    

    【讨论】:

    • 它对我不起作用。我认为这是 typeScript 错误,但我不知道如何修复它
    【解决方案2】:

    试试下面的标题代码:

    httpOptions: {
      headers:{
        accept: 'application/pdf'
      }
      responseType: 'blob',
    }
    

    【讨论】:

    • 它对我不起作用,更像是 typeScript 错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2015-01-13
    • 1970-01-01
    • 2021-01-08
    • 2018-11-12
    • 1970-01-01
    相关资源
    最近更新 更多