Database Spring引导多部分文件上载以及json数据
我想使用SpringBoot多部分文件上传作为json正文的一部分来编写api,还想将img url保存在数据库中。 如下所示的请求:Database Spring引导多部分文件上载以及json数据,database,angular,spring-boot,Database,Angular,Spring Boot,我想使用SpringBoot多部分文件上传作为json正文的一部分来编写api,还想将img url保存在数据库中。 如下所示的请求: ------WebKitFormBoundarynBsAcX7rJhOGsmfY Content-Disposition: form-data; name="fdata"; filename="blob" Content-Type: application/json {"firstname":"saurabh","lastname":"mishra","mob
------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--
请帮我找到解决办法。我用这种方法解决这个问题 我的API方法 我的FileWithObject DTO
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({“文件”、“文件”、“数据”})
公共类FileWithObject{
@JsonProperty(“文件”)
私有多部分文件;
@JsonProperty(“文件”)
私有多部分文件[]文件;
@JsonRawValue
@JsonProperty(“数据”)
私有T数据;
//getter/setter和其他。。。
}
注意:-对于数据参数,可以使用singleFileUploadWithObject方法中的映射过程
希望对你和其他人有帮助
1)在发布时使用{}格式化程序格式化代码。2) 包括你自己解决问题的尝试,以及你受到打击的地方
@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;
}
@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...
}