Spring Angular 4上传图片?

时间:2018-02-22 23:01:12

标签: spring angular spring-data-jpa

如何使用Angular 4上传图片?

<input type="file" (change)="uplod($event)"/>

Spring代码:

@RequestMapping(value="/Etablissement/upload", method=RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Object> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
    File convertFile = new File("C:/Users/acer/reservationF/reservation/reservation/image"+file.getOriginalFilename());
    convertFile.createNewFile();
    FileOutputStream fout = new FileOutputStream(convertFile);
    fout.write(file.getBytes());
    fout.close();
    return new ResponseEntity<>("File is uploaded successfully", HttpStatus.OK);
}

1 个答案:

答案 0 :(得分:0)

我找到了一些修改后的解决方案 Angular 4 – Upload/Get MultipartFile to/from Spring Boot Server