簡體   English   中英

上傳文件時,內容類型發送為“multipart/form-data”時找不到邊界錯誤。如何解決此錯誤?

[英]While uploading file getting error as boundary not found when content-type sent as “multipart/form-data”.How to solve this error?

upload(){  

    console.log("file selected :", this.doc_upload_file);
    let filearray=JSON.parse(JSON.stringify(this.doc_upload_file));
    console.log("................",filearray);

    console.log("form selected :", this.form);

    this.onSubmit(this.form);

  }

 this.url = this.main_url +'/entities/upload?id='+entityid+'&entityType='+entitytype+'&docType='+documenttype;
    var authorization = 'Bearer '+this.sharedService.access_token;
    const headers = new Headers({'Content-Type' : 'multipart/form-data',"Authorization": authorization});

    return this.http.post(this.url,this.body,{headers:headers})
        .pipe(map(
            (response) => {
                // var data = response.json();
                console.log('uploadDocuments: ', response);
                console.log('status: ', response.status);
                return response.status;
            },
            (error) => {
                console.log(error.json());
            }
        ));

錯誤 -

error: "Internal Server Error" exception: "org.springframework.web.multipart.MultipartException" message: "Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload .FileUploadException:請求被拒絕,因為沒有找到多部分邊界”

我認為您需要發送一個 FormData 來解決您的問題。

有人這樣想:

let item = event.target.files[0];
var formData = new FormData();

formData.append(item.name, item, item.name);

        ...


return this.http.post(this.url, formData ,{headers:headers})
        .pipe(map(
          (response) => {
                  ...
          },
       (error) => {
        ...
       }
));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM