| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | //import cn.hutool.core.io.FileUtil; |
| | | import com.aliyun.oss.OSSException; |
| | | import com.obs.services.exception.ObsException; |
| | | import com.obs.services.model.PutObjectResult; |
| | | import com.qxueyou.scc.base.model.FileMeta; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.base.util.ClientUtils; |
| | | import com.qxueyou.scc.teach.res.service.HweiYunOBSService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | @RestController |
| | | @RequestMapping("/file")// @RequestMapping("/file") |
| | | public class HweiYunOBSController { |
| | | private final Logger log = LogManager.getLogger("FileController"); |
| | | |
| | | @Resource |
| | | private HweiYunOBSService hweiYunOBSService; |
| | |
| | | if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { |
| | | return null; |
| | | } |
| | | |
| | | // if (FileUtil.isEmpty(file)) { |
| | | // return new Result(false,"文件为空"); |
| | | // } |
| | |
| | | return test; |
| | | } |
| | | |
| | | // @RequestMapping(value = "fenpian", method = RequestMethod.POST) |
| | | // public Map<String, Object> fpsave(@RequestParam(value = "file", required = false) MultipartFile file) throws IOException { |
| | | // |
| | | // if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { |
| | | // return null; |
| | | // } |
| | | // |
| | | //// if (FileUtil.isEmpty(file)) { |
| | | //// return new Result(false,"文件为空"); |
| | | //// } |
| | | //// final List<FileMeta> test = hweiYunOBSService.fileUpload(file, file.getOriginalFilename()); |
| | | // Map<String, Object> fnepian = hweiYunOBSService.fnepian(file, file.getOriginalFilename()); |
| | | //// return ResponseVO.ok("执行成功",test); |
| | | // return fnepian; |
| | | // } |
| | | /** |
| | | * 文件上传接口:为客户端提供多线程分片上传接口 |
| | | * 返回状态值:200代表成功,500代表上传失败,205代表需重新尝试 |
| | | * |
| | | * @param identifier 唯一id,需客户端保证唯一性,相同文件保证唯一即可,非MD5 |
| | | * @return |
| | | * @TODO : 目前缺少对 各模块文件个数、文件格式、文件大小的上传控制,统一增加在configFileModule表里面即可实现 1 图片; 2 文档 3 视频 4 音频 |
| | | */ |
| | | @RequestMapping(value = "/uploadChunk", headers = "content-type=multipart/*", method = RequestMethod.POST) |
| | | public @ResponseBody FileMeta doUploadPublic(MultipartFile file, HttpServletResponse response, |
| | | Integer chunkNumber, Integer totalChunks, long chunkSize, long totalSize, String identifier, String filename, Integer currentChunkSize) { |
| | | |
| | | FileMeta fileMeta = new FileMeta(); |
| | | try { |
| | | |
| | | Result uploadResult = null; |
| | | |
| | | uploadResult = hweiYunOBSService.uploadChunk(file.getInputStream(), identifier.concat(ClientUtils.getUserId()), chunkNumber, currentChunkSize, totalChunks, filename); |
| | | |
| | | |
| | | fileMeta.setFileId(uploadResult.getDataT("fileId")); |
| | | fileMeta.setPath(uploadResult.getDataT("path")); |
| | | |
| | | if (!uploadResult.isSuccess()) { |
| | | response.setStatus(205); |
| | | } |
| | | |
| | | } catch (OSSException e) { |
| | | response.setStatus(500); |
| | | log.error(e, e); |
| | | } catch (Exception e) { |
| | | log.error("上传模块解析出错:" + e.getMessage(), e); |
| | | response.setStatus(500); |
| | | } |
| | | |
| | | fileMeta.setFileName(filename); |
| | | fileMeta.setFileSize(String.valueOf(totalSize)); |
| | | fileMeta.setFileType(null); |
| | | |
| | | return fileMeta; |
| | | } |
| | | |
| | | /** |
| | | * 初始化分片上传任务 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/uploadChunk/init", method = RequestMethod.POST) |
| | | public @ResponseBody |
| | | Result initUploadChunk(String identifier, String fileName,String md5) { |
| | | |
| | | //如果MD5的对应文件存在则直接返回 |
| | | // Result result = fileService.checkMd5(md5,fileName); |
| | | |
| | | return hweiYunOBSService.initUploadChunk(identifier.concat(ClientUtils.getUserId()), fileName,md5); |
| | | |
| | | } |
| | | |
| | | @RequestMapping(value = "delete", method = RequestMethod.POST) |
| | | public Result delete(@RequestParam(value = "fileName", required = false) String fileName) { |