webupload大文件分片上传
来源:互联网 发布:流程优化六步法 编辑:程序博客网 时间:2024/05/17 00:17
webupload大文件分片上传
1. 大文件分片上传的js代码
2.大文件上传的java后台代码
public String fileUpload(@RequestParam("file") MultipartFile file, String chunks, String chunk, String name, HttpServletRequest request, HttpServletResponse response, String fileType) throws IOException { log.info("FileManageController.fileUpload request={}", request); InputStream proIn = getClass().getClassLoader().getResourceAsStream("uploadConfig.properties"); Properties properties = new Properties(); properties.load(proIn); String fileSystemPath = properties.getProperty("fileManagerSystemPath");//系统根路径 String tempFileSystemPath = properties.getProperty("uploadFileSystemPath");//系统根路径 String fileName = file.getOriginalFilename(); String savePath = fileSystemPath + "/" + fileType; JSONObject json = new JSONObject(); File retfile = new File(savePath, fileName); //为了创建存放的文件夹 if (!retfile.exists()) { retfile.mkdirs(); } json.put("filePath", retfile.getPath()); try { if (null != file) { //判断上传的文件是否被分片(小于5M的不会分片)不分片的上传 if (null == chunks && null == chunk) { File targetFile = new File(savePath, fileName); if (!targetFile.exists()) { targetFile.mkdirs(); } file.transferTo(targetFile); targetFile.createNewFile(); json.put("msg", "success"); return json.toJSONString(); } //分片处理// String tempFileDir = fileSystemPath + File.separator+ System.currentTimeMillis() + File.separator + name; String tempFileDir = tempFileSystemPath + File.separator + name; File parentFileDir = new File(tempFileDir); if (!parentFileDir.exists()) { parentFileDir.mkdirs(); } File f = new File(tempFileDir + File.separator + name + "_" + chunk + ".part"); file.transferTo(f); f.createNewFile(); // 是否全部上传完成 // 所有分片都存在才说明整个文件上传完成 boolean uploadDone = true; for (int i = 0; i < Integer.parseInt(chunks); i++) { File partFile = new File(tempFileDir, name + "_" + i + ".part"); if (!partFile.exists()) { uploadDone = false; json.put("msg", "success"); return json.toJSONString(); } } // 所有分片文件都上传完成 // 将所有分片文件合并到一个文件中 if (uploadDone) { synchronized (this) { File destTempFile = new File(savePath, name); for (int i = 0; i < Integer.parseInt(chunks); i++) { File partFile = new File(tempFileDir, name + "_" + i + ".part"); if (retfile.exists() && i == 0) { retfile.delete(); retfile.createNewFile(); } FileOutputStream destTempfos = new FileOutputStream(destTempFile, true); FileUtils.copyFile(partFile, destTempfos); destTempfos.close(); } FileUtils.deleteDirectory(parentFileDir); } } json.put("msg", "success"); log.info("FileManageController.fileUpload response={}", json.toJSONString()); return json.toJSONString(); } } catch (Exception e) { e.printStackTrace(); log.error("FileManageController.fileUpload error={}", e.getMessage()); } json.put("msg", "success"); return json.toJSONString(); }
阅读全文
0 0
- webupload大文件分片上传
- Webupload+PHP上传大文件
- webupload大文件上传的坑
- 大文件上传插件webupload插件
- Webupload 文件上传
- WebUpload文件上传
- webupload 上传文件
- webuploader分片上传大文件
- 大文件分片上传服务器
- Servlet实现webupload文件上传
- webuploader 实现大文件 分片上传
- iOS大文件分片上传和断点续传
- 大文件分片断点上传显示进度条
- 大文件分片上传和断点续传
- iOS大文件分片上传和断点续传
- Python实现大文件分片上传
- 前段WebUploader;JavaEE大文件分片上传接收
- HttpUrlconnection 实现大文件分片断点上传,支持Https
- python subprocess模块
- javaweb开发session超时时间设置和优先级
- CentOS 7 Linux 安装Nginx
- 用内部类来间接的实现多继承
- tcp窗口滑动以及拥塞控制
- webupload大文件分片上传
- oracle中对表的基本操作
- 安卓混合开发设置返回键为返回上一网页
- springboot AOP+日志的注解实现
- ListView的使用技巧
- 今天预计有多少人买饭团?李彦宏说百度用PaddlePaddle给答案
- 哈萨比斯首次解读AlphaZero竟被当场diss,他起身当面回击说…
- vue 回到顶部 组件
- Java 进度条控件的使用