【发布时间】:2018-06-12 12:57:01
【问题描述】:
我想上传一个 .png 文件并存储它。当我使用 content-type=multipart/form-data 发送它时,我收到了这个异常
org.springframework.web.HttpMediaTypeNotSupportedException: Content type
'application/octet-stream' not supported .
我认为我的应用程序不理解表单数据 contentType 并引发了不相关的异常。怎么了?
@Controller
public class ProfileController {
private static final Logger logger = LoggerFactory.getLogger(ProfileController.class);
@Autowired
ProfileService service;
//http : http --pretty all --form PUT localhost:8080/profile/v1?thumb=glb
@PutMapping(value = "/v1")
public Mono<ResponseEntity<String>> upload(@RequestPart(value = "thumb", required = false) String thumbFilterName,
@RequestPart(value = "genthumb", required = false) String genthumb,
@RequestPart("hash") String hash,
@RequestPart("uploader") Long uploader,
@RequestPart("file") MultipartFile file) throws Exception {
System.out.println(thumbFilterName);
System.out.println(gentumb);
System.out.println(uploader);
System.out.println(file);
//and doing storage stuff!
return Mono.just(ResponseEntity.ok().build());
}
}
这是我用来发送文件的 Rest Client。注意回复。
这些是restClient的截图。使用 restClient 发送文件:
这是设置标题
【问题讨论】:
标签: java rest spring-boot storage multipartform-data