【问题标题】:send an Image file in the body of a http post request in Angular 8在Angular 8中的http post请求正文中发送图像文件
【发布时间】:2020-05-18 21:20:39
【问题描述】:

这是我尝试在正文中添加的对象

firebaseId:“gSECLs1cH9epvlIXX85yx820Tvt2” 说明:未定义 类别:“投票” Imageone: File {name: "21.jpg", lastModified: 1524755773798, lastModifiedDate: Thu Apr 26 2018 20:46:13 GMT+0530 (India Standard Time), webkitRelativePath: "", size: 171456, ...} TaskMadeDate:2020 年 2 月 3 日星期一 11:10:29 GMT+0530(印度标准时间){} 批准:错误

这是发布请求的对象

firebaseId:“gSECLs1cH9epvlIXX85yx820Tvt2” 类别:“投票” 图片一:{} 任务制造日期:“2020-02-03T05:40:29.943Z” 批准:错误

Imageone 变空。

这是我的发帖方式

返回 this.http.post(this._baseUrl + url, 数据) 。管道( 点击((res) => console.log(added = ${res})), catchError(this.handleError('post')) );

【问题讨论】:

  • 您在 Imageone 中发送什么以及如何发送?
  • 我尝试在 Imageone 中发送图像文件

标签: angular file post file-upload image-upload


【解决方案1】:

您是在常规请求中发送文件,而不是像这样使用表单数据来传递文件:

var formData = new FormData()
formData.append('firebaseId',this.firebaseId);
formData.append('imageone',this.imageone);

像这样添加您的所有数据,如果您仍然没有在后端获取文件,则将其添加到您的请求标头中。

'Content-Type': 'application/x-www-form-urlencoded'

【讨论】:

    猜你喜欢
    • 2018-06-19
    • 1970-01-01
    • 2020-03-22
    • 2021-03-12
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2014-09-29
    相关资源
    最近更新 更多