[英]Spring boot Multipart file upload along with json data
I want to write api using Spring boot Multipart file upload as part of json body and also want to save img url in database. 我想使用Spring Boot Multipart文件上传作为json主体的一部分来编写api,也想将img url保存在数据库中。 Requests that look like this:
看起来像这样的请求:
------WebKitFormBoundarynBsAcX7rJhOGsmfY
Content-Disposition: form-data; name="fdata"; filename="blob"
Content-Type: application/json
{"firstname":"saurabh","lastname":"mishra","mobile":"943847557"}
------WebKitFormBoundarynBsAcX7rJhOGsmfY
Content-Disposition: form-data; name="files"; filename="download.jpg"
Content-Type: image/jpeg
------WebKitFormBoundarynBsAcX7rJhOGsmfY--
Please help me to find the solution. 请帮助我找到解决方案。
I solve this issue in this way. 我以这种方式解决了这个问题。
My API Method
我的API方法
@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/singleFileUploadWithObject/{folder}",
method = RequestMethod.POST)
@ResponseBody
public String singleFileUploadWithObject(
@PathVariable(name="bucket-uuid", required = true) String bucketUUId,
@PathVariable(name="folder", required = false) String folder,
FileWithObject rawData) {
return pingResponse;
}
My FileWithObject DTO
我的FileWithObject DTO
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "file", "files", "data" })
public class FileWithObject<T> {
@JsonProperty("file")
private MultipartFile file;
@JsonProperty("files")
private MultipartFile[] files;
@JsonRawValue
@JsonProperty("data")
private T data;
// getter/setter and other...
}
Note:- For data parameter you can use the mapping process in the singleFileUploadWithObject method hope it's help you and other
注意:-对于数据参数,您可以在singleFileUploadWithObject方法中使用映射过程,希望对您和其他人有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.