将curl命令转换为angular post http请求

64jmpszr  于 2022-11-13  发布在  Angular
关注(0)|答案(1)|浏览(200)

我不知道我做错了什么,我只是想把这个curl命令转换成angular post请求中的工作。
curl 命令

curl -F file=@someFile.txt https://store1.gofile.io/uploadFile

Angular 服务方法

url = "https://store1.gofile.io/uploadFile"
  getFile(file:File){
    return this.http.post(this.url,{
      params:{
        'file':file
      }
    });
  }
egmofgnx

egmofgnx1#

您需要以data的形式发送文件,而不是以参数的形式发送。如果您有queryParams,您可以将其添加到options中。这是您要查找的代码。您不需要选项,这只是如果您想实现一个上传进度条/百分比。

const options = {
      reportProgress: true,
      observe: 'events'
    }
    this.http.post('https://store1.gofile.io/uploadFile', file, options)

相关问题