首页 > 解决方案 > 当前请求不是角度的多部分请求错误

问题描述

我正在尝试将图像发送到我的服务器。我不断收到错误消息:当前请求不是多部分请求。

使用的标头:

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
...

标签: angularmultipartform-data

解决方案


推荐阅读