|
@@ -26,12 +26,16 @@ public class UploadServiceImpl implements UploadService {
|
|
|
if (file.isEmpty()) {
|
|
|
throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "文件不能为空");
|
|
|
}
|
|
|
+ //文件大小上限1M
|
|
|
+ if (file.getSize() > 1024 * 1024) {
|
|
|
+ throw new CommonException(ServiceErrorCode.FILE_MAX_SIZE_LIMIT, "文件上传失败,超出大小限制1MB");
|
|
|
+ }
|
|
|
try {
|
|
|
// Get the file and save it somewhere
|
|
|
path = saveFile(file);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("upload file failed", e);
|
|
|
- throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "upload file failed");
|
|
|
+ log.error("文件上传失败", e);
|
|
|
+ throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "文件上传失败,请重新上传");
|
|
|
}
|
|
|
return path;
|
|
|
}
|
|
@@ -57,12 +61,12 @@ public class UploadServiceImpl implements UploadService {
|
|
|
try {
|
|
|
fileAbsolutePath = FastDFSClient.upload(file); //upload to fastdfs
|
|
|
} catch (Exception e) {
|
|
|
- log.error("upload file Exception!", e);
|
|
|
- throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "upload file Exception");
|
|
|
+ log.error("文件上传异常", e);
|
|
|
+ throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "文件上传异常");
|
|
|
}
|
|
|
if (fileAbsolutePath == null) {
|
|
|
- log.error("upload file failed,please upload again!");
|
|
|
- throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "upload file failed,please upload again");
|
|
|
+ log.error("文件上传失败,请重新上传");
|
|
|
+ throw new CommonException(ServiceErrorCode.FILE_UPLOAD_ERROE, "文件上传失败,请重新上传");
|
|
|
}
|
|
|
String path = "/" + fileAbsolutePath[0] + "/" + fileAbsolutePath[1];
|
|
|
return path;
|
|
@@ -85,8 +89,8 @@ public class UploadServiceImpl implements UploadService {
|
|
|
FastDFSClient.deleteFile(groupName, fileName);
|
|
|
} catch (Exception e) {
|
|
|
log.error("", e);
|
|
|
- throw new CommonException(ServiceErrorCode.FILE_DELETE_ERROR, "delete file failed");
|
|
|
+ throw new CommonException(ServiceErrorCode.FILE_DELETE_ERROR, "文件删除失败");
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-}
|
|
|
+}
|