this.uploader.on(‘uploadProgress’, (data, percentage) => {
console.log(‘uploadProgress’);
this.onProgress({ data, percentage });
});
this.uploader.on(‘error’, err => {
this.onError({ msg: ‘上传出错,请重试’ });
});
this.uploader.addFiles(this.file);
this.uploader.upload();
}
cancel = () => {
console.log(‘call cancel’);
this.uploader.stop(true);
this.uploader.destroy();
console.log(‘getStats’, this.uploader.getStats());
}
}
export default Uploader;
在 @/utils/constant 文件中定义了上述代码中所使用的常量,代码如下:
const constants = {
BPR_BASE_URL: ‘/v1.0/sys/admin/files/breakpointRenewal’,
};
module.exports = constants;
到这里前端代码就写完了。
二、后端代码
1、maven依赖
com.aliyun.oss
aliyun-sdk-oss
3.11.0
commons-fileupload
commons-fileupload
1.3.1
commons-lang
commons-lang
2.6
compile
2、ResponseEnum代码
/**
-
@Description: 返回码常量类
-
@Author: henry
-
@Date: 2019/6/21
-
code范围:
-
成功:200
-
公共:0001-0999
-
PaaS
-
FM 103400-103599
*/
public enum ResponseEnum {
/**
- 公共模块码
*/
RESPONSE_CODE_FAIL(100, “请求失败”),
RESPONSE_CODE_SUCCESS(200, “请求成功”),
RESPONSE_CODE_PARAM_ERR(400, “请求参数错误”),
RESPONSE_CODE_PARAM_VALUE_ERR(401, “参数值错误”),
RESPONSE_CODE_PARAM_EMPTY(402, “缺少参数”),
RESPONSE_CODE_NOT_FOUND(404, “找不到指定的资源”),
RESPONSE_CODE_METHOD_NOT_SUPPORT(405, “请求方法不支持”),
RESPONSE_CODE_TYPE_NOT_ACCEPTABLE(406, “请求类型不接受”),
RESPONSE_CODE_METHOD_NOT_EXIST(407, “请求方法不存在”),
RESPONSE_CODE_PARAM_NOT_NULL(430, “参数为空”),
RESPONSE_CODE_RECORD_ALREADY_EXISTS(431, “数据已存在”),
RESPONSE_CODE_RECORD_NOT_EXISTS(432, “数据不存在”),
RESPONSE_CODE_JSON_ERROR(433, “JSON格式不正确”),
RESPONSE_CODE_PARAM_LENGTH_TOO_MIN(434, “参数长度过短”),
RESPONSE_CODE_PARAM_LENGTH_TOO_MAX(435, “参数长度过长”),
RESPONSE_CODE_NOTLANK_PARAM_NOT_EXISTS(436, “必填参数不存在”),
RESPONSE_CODE_VERIFICATION_CODE_ERROR(442, “验证码无效”),
RESPONSE_CODE_SYSTEM_BUSY(459, “系统忙或访问超时,请稍候重试”),
RESPONSE_CODE_SYSTEM_ERROR(500, “系统错误,请稍后再试”),
RESPONSE_CODE_PERMISSION_DENIED(502, “没有该操作的权限”),
/**
- FM(103400-103599)
*/
RESPONSE_CODE_FILE_UPLOAD_ERROR(103400, “文件上传失败”),
RESPONSE_CODE_FILE_DOWNLOAD_ERROR(103401, “文件下载失败”),
RESPONSE_CODE_FILE_DELETE_ERROR(103402, “文件删除失败”),
RESPONSE_CODE_FILE_LIST_QUERY_ERROR(103403, “文件列表查询失败”),
RESPONSE_CODE_BREAKPOINT_RENEVAL_REGISTRATION_ERROR(103404, “断点叙传注册:注册文件已存在”),
RESPONSE_CODE_MERGE_FILE_ERROR(103405, “断点叙传合并:文件合并失败”),
RESPONSE_CODE_FILE_BLOCK_DOES_NOT_EXIST_ERROR(103406, “断点叙传合并:文件分块不存在”),
RESPONSE_CODE_VERIFY_FILE_ERROR(103407, “断点叙传校验:文件校验失败”),
RESPONSE_CODE_PICTURE_SUFFIX_ERROR(103408, “图片格式不正确”);
@Getter
private int code;
@Getter
private String msg;
ResponseEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
}
3、ResponseResult代码
/**
-
@Classname: com.openailab.oascloud.common.model.ResponseResult
-
@Description: 统一返回结果
-
@Author: zxzhang
-
@Date: 2019/6/26
*/
@Component
public class ResponseResult implements Serializable {
private static final long serialVersionUID = 5836869421731990598L;
/**
- 状态描述
*/
@Getter
private String message;
/**
- 返回数据
*/
@Getter
private Object data;
/**
- 响应码
*/
@Getter
private int code;
/**
- 状态(0:失败、1:成功)
*/
@Getter
private int status;
/**
- 总条数
*/
@Getter
private Integer total;
public ResponseResult() {
}
public ResponseResult(int status, Object data) {
this.status = status;
this.data = data;
}
public ResponseResult(int status, String message, Object data) {
this.status = status;
this.message = message;
this.data = data;
}
public ResponseResult(String message, Object data, int code, int status) {
this.message = message;
this.data = data;
this.code = code;
this.status = status;
}
public ResponseResult(String message, Object data, int code, int status, Integer total) {
this.message = message;
this.data = data;
this.code = code;
this.status = status;
this.total = total;
}
public static ResponseResult fail(String msg) {
if (StringUtils.isEmpty(msg)) {
return new ResponseResult(ResponseEnum.RESPONSE_CODE_FAIL.getMsg(), null, ResponseEnum.RESPONSE_CODE_FAIL.getCode(), CommonConst.RESPONSE_FAIL);
} else {
return new ResponseResult(msg, null, ResponseEnum.RESPONSE_CODE_FAIL.getCode(), CommonConst.RESPONSE_FAIL);
}
}
public static ResponseResult fail(int code, String msg) {
return new ResponseResult(msg, null, code, CommonConst.RESPONSE_FAIL);
}
public static ResponseResult fail(ResponseEnum responseEnum, Object obj) {
return new ResponseResult(responseEnum.getMsg(), obj, responseEnum.getCode(), 0);
}
public static ResponseResult success(Object data) {
return new ResponseResult(ResponseEnum.RESPONSE_CODE_SUCCESS.getMsg(), data, ResponseEnum.RESPONSE_CODE_SUCCESS.getCode(), CommonConst.RESPONSE_SUCCESS);
}
public static ResponseResult success(Object data, int code, String message) {
return new ResponseResult(message, data, code, CommonConst.RESPONSE_SUCCESS);
}
public ResponseResult setMessage(String message) {
this.message = message;
return this;
}
public ResponseResult setData(Object data) {
this.data = data;
return this;
}
public ResponseResult setStatus(int status) {
this.status = status;
return this;
}
public ResponseResult setCode(int code) {
this.code = code;
return this;
}
public ResponseResult setTotal(Integer total) {
this.total = total;
return this;
}
}
4、FileController代码
/**
-
@description: 文件管理-Controller
-
@author: zhangzhixiang
-
@createDate: 2019/12/9
-
@version: 1.0
*/
@RestController
@RequestMapping(“/v1.0/sys/admin/files”)
public class FileController {
private static Logger LOG = LoggerFactory.getLogger(FileController.class);
@Autowired
private IFileService fileService;
@Autowired
private IUserService userService;
/**
-
断点叙传
-
@param file
-
@param fileMd5
<