ajaxfileupload文件上传插件,解决再次提交文件流置空的问题
来源:互联网 发布:table用js做点击事件 编辑:程序博客网 时间:2024/06/16 13:37
1、在ajaxfilesupload.js文件中,修改如下代码:
2、上传代码展示:
<script type="text/javascript"src="<%=path %>/js/upload/ajaxfilesupload.js"></script>
Html代码:
<inputtype='file' id='file' name='file' runat='server' accept='image/png,image/gif,image/jpg,image/jpeg' capture='camera'onchange='handleFiles(this)'/>
Js代码:
多文件上传需获取所有file的id:
vararrId = [];
$("input[name='fileupload']").each(function(){
arrId.push($(this).attr("id"));
});
$.ajaxFileUpload({
url :path+'/person/editheadpic.do',
secureuri : false,//安全协议
fileElementId:,//id 'file'/arrId
dataType:'text',
type : 'POST',
success : function(data, status) {
varjson = "";
var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf('ucbrowser') > -1&& ua.match('android')){
json =data.substring(data.lastIndexOf(">")+4);
json = eval('(' + json +')');
}else {
json =jQuery.parseJSON(jQuery(data).text());
}
//返回结果的相应操作
}
});
Java代码:
//单文件上传上传文件
MultipartHttpServletRequest multipartRequest= (MultipartHttpServletRequest) req;
MultipartFile file =multipartRequest.getFile("file");
if (file.getSize() > 0)
{
// 文件名称
String fileName =file.getOriginalFilename();
// 本地存储路径
SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdf2 = newSimpleDateFormat("HHmmssSSS");
String dateStr =sdf2.format(new Date());
String path =req.getSession().getServletContext().getRealPath("") + File.separator+ "wap"
+ File.separator+ "user" + File.separator + sdf.format(new Date()) + File.separator;
File pathfile = newFile(path);
// 如果文件目录不存在,则新建
if (!pathfile.exists()&& !pathfile.isDirectory())
{
pathfile.mkdirs();
}
// 先存入本地
String fpath = path +dateStr + fileName.substring(fileName.lastIndexOf("."));
File newFile = newFile(fpath);
if (!newFile.exists())
{
newFile.createNewFile();
}
// 上传文件
FileOutputStreamoutputStream = new FileOutputStream(newFile);
FileCopyUtils.copy(file.getInputStream(), outputStream);
// 指定对应模块的文件夹
Map<String, String>param = new HashMap<String, String>();
param.put("fileTypeName", "center");
// 上传图片后的图片地址
String picUrl =UploadUtil.uploadFile(fpath, "img", req, param);
//多文件上传
// 转型为MultipartHttpRequest(重点的所在)
MultipartHttpServletRequestmultipartRequest = (MultipartHttpServletRequest) req;
try
{
// 循环上传图片
for (Iterator<String> it =multipartRequest.getFileNames(); it.hasNext();)
{
String key = it.next();
MultipartFile file =multipartRequest.getFile(key);
if(file.getOriginalFilename().length() > 0)
{
// 文件名称
String fileName =file.getOriginalFilename();
// 先存入本地
String fpath = path +sdf2.format(nowDate) + key +fileName.substring(fileName.lastIndexOf("."));
File newFile = new File(fpath);
if (!newFile.exists())
{
newFile.createNewFile();
}
FileOutputStreamoutputStream = new FileOutputStream(newFile);
FileCopyUtils.copy(file.getInputStream(), outputStream);
// 指定对应模块的文件夹
Map<String, String>param = new HashMap<String, String>();
param.put("fileTypeName", "return");
// 上传图片后的图片地址
String picUrl =UploadUtil.uploadFile(fpath, "img", req, param);
if(!StringTools.isNullOrEmpty(picUrl))
{
affixurl +="," + picUrl;
}
}
}
}
catch (IOException e)
{
logger.error("上传文件流异常",e);
}
// 判断非空,截取第一逗号
if(!StringTools.isNullOrEmpty(affixurl))
{
affixurl = affixurl.substring(1);
}
- ajaxfileupload文件上传插件,解决再次提交文件流置空的问题
- ajaxFileUpload插件上传文件
- 解决ajaxfileupload二次上传文件问题
- jQuery上传文件插件AjaxFileUpload的使用
- jQuery的插件ajaxFileupload上传文件
- ajaxFileUpload Jquery文件上传插件
- ajaxFileUpload文件上传Jquery插件
- jQuery 文件上传插件ajaxFileUpload使用以及onchange问题
- ajaxfileupload文件上传及带参提交
- 利用Jquery ajaxfileupload插件+PHP 进行文件的上传
- jquery ajaxFileUpload.js插件支持多文件上传的方法
- ajaxfileupload -- 一款不错的AJAX文件上传插件
- 文件上传JQuery插件 ajaxFileUpload 不严谨的bug
- ajaxFileUpload ajax上传文件!jquery插件
- jQuery插件AjaxFileUpload实现文件上传
- jquery插件AjaxFileUpload实现ajax文件上传
- ajax文件上传,采用ajaxfileupload插件
- ajaxfileupload.js 文件上传插件之改进
- 工作日记2017.08.21 Google Guava
- HttpClient
- leetcode 409. Longest Palindrome
- Android源码目录结构详解
- opengl对图像进行模糊处理
- ajaxfileupload文件上传插件,解决再次提交文件流置空的问题
- 常见状态码
- 汉明码详细讲解
- collectionView 无限轮播设计思路
- http://www.revolvermaps.com/
- 完全卸载删除gitlab
- C#加载图片时,对同一图片,绝对路径没问题,相对路径报错。
- HTTP和HTTPS有什么区别? 什么是SSL证书?使用ssl证书优势?
- 支付宝与微信支付及原路退款(一)