我正在開發一個Spring-MVC應用程序,其中有文件上傳功能。爲此,我想確定用戶上傳的文件是否是一種圖像。Java,MultiPart:確定多部分上傳是否是一種圖像
我想創建該圖像的縮略圖預覽,這就是爲什麼我需要確定它是否是圖像。我有我的縮略圖創建代碼,只是無所知,如果它是一個圖像。
請求代碼:
@RequestMapping(value = "/notes/addattachment/{noteid}/{groupaccountid}/{api}", method = RequestMethod.POST)
public @ResponseBody void addAttachments(@PathVariable("noteid") int noteid, @PathVariable("groupaccountid") Long groupAccountId,
@PathVariable("api") String api, @RequestParam("attachments") MultipartFile attachment) {
if (!(attachment.isEmpty())) {
switch (api){
case "somecase":
try {
String fileName = attachment.getOriginalFilename();
long fileSize = attachment.getSize();
byte[] bytes = attachment.getBytes();
this.groupAttachmentsService.addAttachment(bytes, fileName, fileSize, noteid, true,attachment.getContentType());
} catch (Exception ignored) {}
break;
case "google":
this.driveQuickstart.insertFile(attachment,noteid, groupAccountId,"123");
break;
case "dropbox":
String path = api.replace(":","/");
this.dropboxTask.insertFile(attachment,"path",noteid, groupAccountId);
break;
}
}
}
任何幫助將是很好。謝謝。
請參閱此示例它對您有用:http://stackoverflow.com/questions/1067655/how-to-upload-a-file-using-java-httpclient-library-working-with-php/ 1068132#1068132 –