Failed to parse multipart servlet request - the request was rejected because no multipart...

Discussão em 'Angular' iniciado por Tania, Abril 1, 2025.

  1. Tania

    Tania Guest

    Does anyone have any idea why I am getting this boundary error when submitting this multipart file?

    Error:

    {errCode: 4000, errMsg: "Failed to parse multipart servlet request", timestamp: "01-04-2025 07:26:30"}

    Caused by: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found


    Angular 17

    importProducts(productId,file:File, tag): Observable<any[]> {

    var url = "http://localhost:9100/importProduct/“+productId+"?tag="+tag;
    var headers: HttpHeaders = new HttpHeaders();
    headers = headers.set('content-type', 'multipart/form-data');
    this.http.combineHeaders(headers);
    return this.http.post(url, file, 'ImportProducts');

    }


    Java17

    @PostMapping(value = "/importProduct/{product_id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity<Object> importProductList(@PathVariable(value = "product_id") String productId,
    @RequestParam(value = "tag") boolean tag, @RequestParam("uploadFile") MultipartFile uploadFile)
    throws IOException {


    if ((uploadFile.getName() == null) || "".equals(uploadFile.getName())) {
    //Error file
    } else if (uploadFile.getSize() == 0) {
    //Error stream null
    } else {
    String newFile = uploadFile.getOriginalFilename();
    if (tag) {
    //Import products process
    return new ResponseEntity<>(true, HttpStatus.OK);
    }
    }
    }


    Thanks a lot if you can help me and thanks for your time.

    Continue reading...

Compartilhe esta Página