我正在使用 Vertx 创建一个 API 来让用户上传图像,但我想限制为某些文件类型 - jpg|Jpeg|png
.
做到这一点的最佳方法是什么?
private void uploadLogoHandler(RoutingContext context) {
//Filter content type
}
HTML:
<input type="file" name="myImage" accept="image/*" />
在 vert.x 上,我们需要检查上传文件的内容类型,假设我们只有一个上传:
Set<FileUpload> fileUploads = routingContext.fileUploads();
FileUpload fileUpload = fileUploads.iterator().next();
fileUpload.contentType();
if(!fileUpload.contentType().startsWith("image/")){
routingContext.response().putHeader("content-type", "text/html").end("Please upload an image.");
}else{
// Process your image
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句