簡體   English   中英

Spring Boot Jhipster映像上傳不起作用

[英]Spring boot Jhipster image upload not working

我想上傳圖片以及更多來自角度的內容。 這是VM對象:

public class UserPictureVM {

    private MultipartFile file;

    private String type;

    private String coverPosition;

這是rest方法:

 @PostMapping("/user/upload-picture")
 @Timed 
 public ResponseEntity<Void> uploadUserPicture(@RequestBody UserPictureVM userPicture){

這是提交表單的Angular方法:

saveCoverImage() {
    const formData: FormData = new FormData();

    formData.append('coverPosition', '0, 0');
    formData.append('file', this.coverForm.file);
    formData.append('type', 'cover');

    this.profileService.uploadImages(formData)
      .subscribe(res=> {
        console.log(res);
      })
  }

但我得到錯誤:

Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;charset=UTF-8' not supported

您正在提交帶有3個請求參數的表單。 因此,您應該將控制器方法簽名更改為此:

  public ResponseEntity<Void> uploadUserPicture(
      @RequestParam("coverPosition") String coverPosition,
      @RequestParam("file") MultipartFile file,
      @RequestParam("type") String type)

暫無
暫無

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

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