plupload批量上传分片功能,

对于文件比较大的情况下,plupload支持分片上传,后台代码如下:

    /**
*
* 方法:upLoadSpecialProgramPictrue
* 方法说明:本地节目导入
* @return
* @author wangHao
* @throws Exception
* @date 2015年6月9日
*/
@RequestMapping("/localUpLoadProgram")
@ResponseBody
public void localUpLoadProgram(
@RequestParam("file") CommonsMultipartFile[] file,
HttpServletResponse response,HttpServletRequest request) throws Exception { boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart){
String fileName = "";
Integer chunk = 0, chunks = 0; //检查文件目录,不存在则创建
String relativePath = "/plupload/files/";
String realPath = ConfigUtil.class.getResource("/").getPath();
File folder = new File(realPath + relativePath);
if (!folder.exists()) {
folder.mkdirs();
} DiskFileItemFactory diskFactory = new DiskFileItemFactory();
// threshold 极限、临界值,即硬盘缓存 1M
diskFactory.setSizeThreshold(4 * 1024); ServletFileUpload upload = new ServletFileUpload(diskFactory);
// 设置允许上传的最大文件大小(单位MB)
upload.setSizeMax(1024 * 1048576);
upload.setHeaderEncoding("UTF-8");
List<FileItem> fileList = new ArrayList<FileItem>();
fileList.add(file[0].getFileItem());
Iterator<FileItem> it = fileList.iterator();
FileItem item = it.next();
String name = item.getFieldName();
InputStream input = item.getInputStream();
fileName = item.getName();
chunk = Integer.parseInt(request.getParameter("chunk"));
chunks = Integer.parseInt(request.getParameter("chunks"));
// 处理上传文件内容
if (!item.isFormField()) {
//目标文件
File destFile = new File(folder, fileName);
//文件已存在删除旧文件(上传了同名的文件)
if (chunk == 0 && destFile.exists()) {
destFile.delete();
destFile = new File(folder, fileName);
}
//合成文件
appendFile(input, destFile);
if (chunk == chunks - 1) {
System.out.println("上传完成");
}else {
System.out.println("还剩["+(chunks-1-chunk)+"]个块文件");
}
}
}
}
private void appendFile(InputStream in, File destFile) {
OutputStream out = null;
try {
// plupload 配置了chunk的时候新上传的文件append到文件末尾
if (destFile.exists()) {
out = new BufferedOutputStream(new FileOutputStream(destFile, true), BUFFER_SIZE);
} else {
out = new BufferedOutputStream(new FileOutputStream(destFile),BUFFER_SIZE);
}
in = new BufferedInputStream(in, BUFFER_SIZE); int len = 0;
byte[] buffer = new byte[BUFFER_SIZE];
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} catch (Exception e) {
} finally {
try {
if (null != in) {
in.close();
}
if(null != out){
out.close();
}
} catch (IOException e) {
}
}
}

plupload批量上传分片(后台代码)的更多相关文章

  1. layui 批量上传文件 + 后台 用servlet3.0接收【我】

    前台代码: [主要参照layui官方 文件上传示例 https://www.layui.com/demo/upload.html] <!DOCTYPE html> <html> ...

  2. asp.net 下载任意格式文件 上传文件后台代码

    思路:将文件转化为流,输出到页面上的iframe中去 //下载附件逻辑 object DownLoad(NameValueCollection nv) { int attachId = nv[&quo ...

  3. WEB版一次选择多个文件进行批量上传(Plupload)的解决方案

    WEB版一次选择多个文件进行批量上传(Plupload)的解决方案  转载自http://www.cnblogs.com/chillsrc/archive/2013/01/30/2883648.htm ...

  4. ecshop 后台批量上传商品 完整上传

    ecshop 后台批量上传商品,之所以无法上传,是因为后台上传php文件方法中没有导入商品原图路径 将ecshop根目录中的admin/goods_batch.php文件全部修改为 <?php ...

  5. ux.plup.File plupload 集成 ux.plup.FileLis 批量上传预览

    //plupload 集成 Ext.define('ux.plup.File', { extend: 'Ext.form.field.Text', xtype: 'plupFile', alias: ...

  6. SpringMVC+Ajax实现文件批量上传和下载功能实例代码

    需求: 文件批量上传,支持断点续传. 文件批量下载,支持断点续传. 使用JS能够实现批量下载,能够提供接口从指定url中下载文件并保存在本地指定路径中. 服务器不需要打包. 支持大文件断点下载.比如下 ...

  7. 文件/图片,批量上传【神器】--WebUploader

    <system.web> <httpRuntime maxRequestLength="102400" executionTimeout="720&qu ...

  8. WEB版一次选择多个文件进行批量上传(WebUploader)的解决方案

    本人在2010年时使用swfupload为核心进行文件的批量上传的解决方案.见文章:WEB版一次选择多个文件进行批量上传(swfupload)的解决方案. 本人在2013年时使用plupload为核心 ...

  9. php实现大文件上传分片上传断点续传

    前段时间做视频上传业务,通过网页上传视频到服务器. 视频大小 小则几十M,大则 1G+,以一般的HTTP请求发送数据的方式的话,会遇到的问题:1,文件过大,超出服务端的请求大小限制:2,请求时间过长, ...

随机推荐

  1. c# 快速修改图片颜色

    public static void ChangeColour(this Bitmap bmp, byte inColourR, byte inColourG, byte inColourB, byt ...

  2. MyBatis 中 sqlmapconfig核心标签typeAliases配置说明

    标签说明 在 MyBatis 的 sql 映射配置文件中,需要使用 paramterType.resultType 来设置 sql 语句的输入输出参数,一般参数都是基本的数据类型或封装类型,但都需要声 ...

  3. javascript对HTML字符转义与反转义

    1.背景:在项目中,经常遇到一些字符需要进行转义后才能显示到界面上,如“&”,在界面中显示的是“&”,在html中书写“&”,显示在界面的中的依然是“&”. 这时候,就 ...

  4. Hadoop的安装与配置(虚拟机中的伪分布模式)

    1引言 hadoop如今已经成为大数据处理中不可缺少的关键技术,在如今大数据爆炸的时代,hadoop给我们处理海量数据提供了强有力的技术支撑.因此,了解hadoop的原理与应用方法是必要的技术知识. ...

  5. 解决Android报错No resource found that matches the given name (at 'text' with value '@string/hello').

    解决Android项目No resource found that matches the given name (at 'text' with value '@string/hello'). 如图, ...

  6. Android学习——Fragment静态加载

    从今天开始做一套安卓的学习笔记,开发环境是Android Studio,把学习过程中的知识和遇到的问题都写在这里,先从Fragment开始学起. Fragment概述 Fragment是Android ...

  7. Matlab函数——awgn(高斯噪声)

    Matlab函数--awgn awgn 将白色高斯噪声添加到信号中 语法  y = awgn(x,snr)  y = awgn(x,snr,sigpower)  y = awgn(x,snr,'mea ...

  8. SolidWorks二次开发的研究

    三维机械设计软件SolidWorks是一套基于Windows的CAD/CAE/CAM/PDM桌面集成系统,是由美国SolidWorks公司在总结和继承大型机械CAD软件的基础上,在Windows环境下 ...

  9. 会话cookie中缺少HttpOnly属性 解决

    会话cookie中缺少HttpOnly属性 解决   只需要写一个过滤器即可 1 package com.neusoft.streamone.framework.security.filter; 2 ...

  10. php配置优化-生产环境应用版

    [global] error_log = log/php-fpm.log log_level = warning emergency_restart_threshold = 10 emergency_ ...