我一直在尋找this,但似乎我的問題在別處。我正在嘗試上傳文件。該input
當前被定義爲:MissingServletRequestPartException:所需的請求部分「文件」不存在
<input
type="file"
style="display: none;"
name="file"
multiple
nv-file-select
uploader="uploader">
這是如何進行上傳:
var uploader = $scope.uploader = new FileUploader({
url: 'http://localhost:8080/rest-api/dl4j/we/uploadModel'
});
uploader.onAfterAddingFile = function($modelFile) {
var fd = new FormData();
fd.append('file', $modelFile.file);
$http.post($modelFile.url, fd, {
headers: {
'Content-Type': undefined
},
transformRequest: angular.identity
})
.then(
function (data) {
alert("upload success");
},
function (data, status) {
alert("upload error");
}
);
};
雖然這是Spring REST端點:
@PostMapping(WordEmbeddingApiPaths.UPLOAD_MODEL)
@RequestMapping(method=RequestMethod.POST, headers={"Content-Type=multipart/form-data"})
public ResponseEntity<WordVectorListDto> uploadModel(
@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
LOGGER.debug("POST uploadModel");
return new ResponseEntity<WordVectorListDto>((WordVectorListDto)null, HttpStatus.OK);
}
的問題是雖然,春天拋出異常,告訴我參數file
不存在:
org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present
這是請求信息:
我怎樣才能讓這個文件上傳的工作?
你完成這件事?我遇到了與我的Angular2應用程序相同的問題 – vigamage