我正在开发一个Spring-MVC应用程序,我有文件上传工具。为此,我想确定用户上传的文件是否是一种图像。
我想创建该图像的缩略图预览,这就是我需要确定它是否是图像的原因。我有缩略图创建代码,只知道它是不是一个图像。
请求代码:
@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;
}
}
}
任何帮助都会很好。谢谢。