angular - 当前请求不是角度的多部分请求错误
问题描述
我正在尝试将图像发送到我的服务器。我不断收到错误消息:当前请求不是多部分请求。
使用的标头:
this.headerss = new HttpHeaders({
"Access-Control-Allow-Origin": "*",
});
这里我没有指定内容类型。
使用方法后:
postFormDataToServerMultiPart(action: string, formData) {
return this.http
.post(HttpService.apiUrl + action, formData, { headers: this.headerss })
.pipe(map((response: any) => response));
}
用于应用 POST 请求的服务方法。
在我的 component.ts 中:
var formData = new FormData();
formData.append("file", this.imageForm.get("profile").value);
console.log(this.imageForm.get("profile").value);
// output of console.log:
File {name: "Ellipse 16@2x.png", lastModified: 1625150174408, lastModifiedDate: Thu Jul 01 2021 17:36:14 GMT+0300 (Eastern European Summer Time), webkitRelativePath: "", size: 1131, …}
lastModified: 1625150174408
lastModifiedDate: Thu Jul 01 2021 17:36:14 GMT+0300 (Eastern European Summer Time) {}
name: "Ellipse 16@2x.png"
size: 1131
type: "image/png"
webkitRelativePath: ""
[[Prototype]]: File
if (this.Image) {
this.httpService
.postFormDataToServerMultiPart(
"api/upload/driver_image?id=" + this.employeeId,
formData
)
.subscribe((resp) => {
console.log("edit", resp);
if (resp.status == "SUCCESS") {
var dialogRef = this.dialog.open(DisplayPopupComponent, {
data: {
title: "Driver Updated Successfully!",
},
});
这一切,经过一段时间的搜索,我没有在我的代码中发现问题,但仍然出现此错误?
Current request is not a multipart request.
注意:我们在后端没有任何问题。
当我在检查中查看我的网络时,我仍然在 header getContent-type:application/json
中。
Request-header:
...
Connection: keep-alive
Content-Length: 1375
Content-Type: application/json
...
解决方案
推荐阅读
- python - 这个损失在 [num_steps, loss, _] = sess.run(.......) 中意味着什么?
- crop - 在 AMP-HTML 中裁剪图像
- java - 使用 Spark / Java 获取每行数据帧的当前时间戳
- javascript - Subtracting 3 days from date
- python - 删除行并根据另一个数据框对一个数据框进行排序
- pyparsing - pyparsing 解析 c/cpp 枚举,其值为用户定义的宏
- ssl - 即使 verifyHostname 为假,为什么还要完成主机名验证?
- java - Spring数据JPA删除查询
- r - 如何在 stringr 中使用常规表达式进行查找/替换
- javascript - 如何设置 mocha 以在 Gatsby 存储库中运行测试