jsp
@At
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" })
public Result upload2Oss(@Param("file") TempFile file) {
String fileType = file.getMeta().getFileExtension();
List allowed = Arrays.asList(allowedImgType);
Collections.sort(allowed);
if (Collections.binarySearch(allowed, fileType) < 0) {
return Result.fail("不允许上传的图片类型 '" + fileType + "' ");
}
String key = OSSUtils.upload(file.getFile());
if (Strings.isBlank(key)) {
return Result.fail("文件上传失败");
}
return Result.success().addData("imageId", key).addData("imgUrl", "http://image.51touchmedia.com/" + key);
}
添加回复
请先登陆