gpt4 book ai didi

Java,多部分 : Determine if multipart uploaded is a type of image

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:24:00 27 4
gpt4 key购买 nike

我正在开发一个具有文件上传功能的 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;


}
}
}

任何帮助都会很好。谢谢。

最佳答案

如果您使用的是 java 7 ImageIO 是您可以用来检查文件是否为图像的类。 ImageIO read()如果找不到图像,此方法返回 null。

关于Java,多部分 : Determine if multipart uploaded is a type of image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32689899/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com