[英]Spring boot - How to validate Multipartfile in rest application
[英]Spring boot and Angularjs Multipartfile and application/xml
這是我春季靴子的控制器
@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "multipart/form-data")
@ResponseBody
public ResponseEntity<?> test(
@RequestParam("enveloppe") Enveloppe enveloppe,
@RequestParam("files") MultipartFile[] uploadFiles) {
}
這是我在angularJs中的服務
var fd = new FormData();
angular.forEach(files, function(file) {
fd.append('files', file);
})
fd.append('enveloppe', enveloppe, {type :'application/xml'} );
$http.post("/test", fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
我的對象“enveloppe”由xsd在spring boot中自動生成。 我的對象“enveloppe”在angularjs中由json2Xml lib轉換為xml。 但是,春天的靴子不能'包裝對象enveloppe。 〜
1)可以這樣做嗎?
是的,這是可能的,但在服務中附加formData,我會說在控制器中做
<input type="file" id="filename">
在你的控制器中
var file=document.getElementById("filename").files[0];
var formData = new FormData();
formData.append("fileKey", file);
然后使用您的服務將數據發送到后端。
我用@RequestPart找到了帶有spring boot的解決方案和第二部分的xml
我的控制器
@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "multipart/form-data")
@ResponseBody
public ResponseEntity<?> test(
@RequestPart("enveloppe") Enveloppe enveloppe,
@RequestPart("files") MultipartFile[] uploadFiles) {
}
angularjs服務
var fd = new FormData();
angular.forEach(files, function(file) {
fd.append('files', file);
})
fd.append('enveloppe', new Blob([enveloppe], {type: 'application/xml'}));
$http.post("/test", fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.