uploadifive上传,无需flash插件案列

前端:
$('#updateFiles').uploadifive({
    'auto': true,  //是否自动上传,默认true
    'multi': true, //是否多文件
    'uploadScript' : '<%=request.getContextPath()%>/fileUpload/uploadFilesWithRealName', //地址
    'buttonText' : '请选择文件',
    'dnd'  : false,//是否允许拖动上传
    'removeCompleted' : false,//上传成功后会自动删除页面上的文件
    'queueID'  : false,
    'fileType':['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'],//文件类型
    'fileObjName':'uploadify',//文件名称
    'fileSizeLimit':'20MB',//文件大小
    'onError'      : function(errorType) {//异常处理
        console.log('The error was: ' + errorType);
    },
    'onFallback': function () { //如果浏览器没有兼容的HTML5文件API功能,则在初始化期间触发
        alert('浏览器不支持HTML5,无法上传!');
    },
    'onProgress' : function(file, e) {//上传进度条和大小
        if (e.lengthComputable) {
            var percent = Math.round((e.loaded / e.total) * 100);
        }
        file.queueItem.find('.fileinfo').html(' - ' + percent + '%');
        file.queueItem.find('.progress-bar').css('width', percent + '%');
    },
    'onUploadComplete' : function(file, data) {//成功处理
        if(data){
            var json=data;
            $('#savePath').val(json);
            $('#fileName').val(file.name);
        }else{
            console.info("失败");
        }
    }
});
后台
/**
 * @desc 多文件上传
 * @return
 */
@RequestMapping(value="/uploadFilesWithRealName")
@ResponseBody
public String uploadFilesWithRealName(MultipartHttpServletRequest request, @MatrixVariable(required=false) String jsessionid) {
   List<String> filePaths = new ArrayList<>();
   try {
      List<MultipartFile> files = request.getFiles("uploadify");
      for (int i = 0; i < files.size(); i++) {
         MultipartFile file = files.get(i);
         // 把文件上传到临时文件夹
         String filePath = FileUtil.saveFileToTempDir(file.getInputStream(), file.getOriginalFilename(), true);
         String aesPath = URLEncoder.encode(AESUtil.getInstance().encrypt(filePath), Constants.CHAR_ENCODING_UTF8);
         filePaths.add(aesPath);
      }
      return StringUtils.join(filePaths, ",");
      // 回传数据失败的时候
   } catch (Exception e) {
      e.printStackTrace();
      return null;
   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值