html file 文件批量上传 以及碰到的一些问题提
//javascript 代码
$("#submite").click(function (evt) { var arrayTr = $("#datatables").find("tbody").find("tr");
$(arrayTr).each(function (index, value) {
var data = new FormData();
$(value).find("input[type='file']").each(function (i, file) {
if (file.files[0] != undefined) {
data.append(file.files[0].name + i, file.files[0]);
}
}); data.append("modelKey", JSON.stringify(datas.data[index])) //apis.certificate.httpRequestPost(apis.certificate.UploadCertificate, data, function () { alert("success") }); $.ajax({
url: apis.certificate.UploadCertificate,
type: "POST",
data: data,
contentType: false,
processData: false,
success: function (result) { alert(result); },
error: function (err) {
alert(err.statusText)
}
}); }); });
提示无法打开关闭的文件流时候 配置
<compilation debug="true" targetFramework="4.5" />
<httpRuntime maxRequestLength="1048576" targetFramework="4.5" requestLengthDiskThreshold="1048576" useFullyQualifiedRedirectUrl="true" executionTimeout="3600" />
</system.web>
后台代码 string json =HttpContext.Current.Request.Form["modelKey"];
modeldo m = Newtonsoft.Json.JsonConvert.DeserializeObject<modeldo>(json);
HttpFileCollection _file = System.Web.HttpContext.Current.Request.Files;
Tuple<modeldo, HttpFileCollection> model = new Tuple<modeldo, HttpFileCollection>(m, _file);
ThreadPool.QueueUserWorkItem(threadDo, model); //这里用异步多线程可能会存在问题 导致后续文件无法完全上传 可以直接调用
}
public void threadDo(object o)
{
HttpFileCollection _file = (HttpFileCollection)(((Tuple<modeldo, HttpFileCollection>)o).Item2);
modeldo m = (modeldo)((Tuple<modeldo, HttpFileCollection>)o).Item1;
for (int i = 0; i < _file.Count; i++)
{
int CatagoryId = Convert.ToInt32(_file.AllKeys[i].Substring(_file.AllKeys[i].Length - 1));
switch (CatagoryId)
{
case 0:
m.CurrentCertificatePutAddress = UploadFile(_file[i]);
m.CurrentCertificatePutAddressName = _file[i].FileName;
break;
case 1:
m.CurrentCostSettleRule = UploadFile(_file[i]);
m.CurrentCostSettleRuleName = _file[i].FileName;
break;
case 2:
m.CurrentCostSettleCertificate = UploadFile(_file[i]);
m.CurrentCostSettleCertificateName = _file[i].FileName;
break;
case 3:
m.CurrentContract = UploadFile(_file[i]);
m.CurrentContractName = _file[i].FileName;
break;
}
}
ConsumptionCertificatedetail certificateModel = new ConsumptionCertificatedetail();
certificateModel.CertificateNumber = m.CertificateNumber;//2017-06-01 - 2017-06-30
certificateModel.CurrentCertificateStart = m.CurrentCertificateSection.Split('~')[0];
certificateModel.CurrentCertificateEnd = m.CurrentCertificateSection.Split('~')[1];
certificateModel.CurrentContract = m.CurrentContract;
certificateModel.CurrentContractName = m.CurrentContractName;
certificateModel.CurrentCertificatePutTxt = m.CurrentCertificatePutTxt;
certificateModel.CurrentCertificatePutAddressName = m.CurrentCertificatePutAddressName;
certificateModel.CurrentCertificatePutAddress = m.CurrentCertificatePutAddress;
certificateModel.CurrentCostSettleCertificate = m.CurrentCostSettleCertificate;
certificateModel.CurrentCostSettleCertificateName = m.CurrentCostSettleCertificateName;
certificateModel.CurrentCostSettleCertificateTxt = m.CurrentCostSettleCertificateTxt;
certificateModel.CurrentCostSettleRule = m.CurrentCostSettleRule;
certificateModel.CurrentCostSettleRuleName = m.CurrentCostSettleRuleName;
certificateModel.CurrentCostSettleRuleTxt = m.CurrentCostSettleRuleTxt;
certificateModel.CurrentPutUrl = m.CurrentPutUrl;
bus.AddcertificateDetail(certificateModel);
//long size = _file[0].ContentLength;
////文件类型
//string type = _file[0].ContentType;
////文件名
//string name = _file[0].FileName;
////文件格式
//string _tp = System.IO.Path.GetExtension(name);
}
public string UploadFile(HttpPostedFile Files)
{
int FileLenth = Files.ContentLength;
byte[] buffur = new byte[FileLenth];
using (BinaryReader br = new BinaryReader(Files.InputStream, Encoding.UTF8))
{
buffur = br.ReadBytes(FileLenth);
br.Close();
br.Dispose();
}
DFSClient client = new DFSClient();
string url= client.UploadFile(buffur, System.IO.Path.GetExtension(Files.FileName).Substring(1, System.IO.Path.GetExtension(Files.FileName).Length-1));
return url;
}
}
public class modeldo : ConsumptionCertificatedetail
{
public string CurrentCertificateSection { get; set; }
}
}
html file 文件批量上传 以及碰到的一些问题提的更多相关文章
- 带进度条的文件批量上传插件uploadify
有时项目中需要一个文件批量上传功能时,个人认为uploadify是快速简便的解决方案. 先上效果图: 一. 下载uploadify 从官网下载uploadify的Flash版本(Flash版本免费,另 ...
- 使用WebUploader实现文件批量上传,进度条显示功能
知识点:利用WebUploader,实现文件批量上传,并且实时显示文件的上传进度 参考官方文档:http://fex.baidu.com/webuploader/ (1)引入三个资源 JS,CSS,S ...
- jquery文件批量上传控件Uploadify3.2(java springMVC)
人比較懒 有用为主 不怎么排版了 先放上Uploadify的官网链接:http://www.uploadify.com/ -->里面能够看到PHP的演示样例,属性说明,以及控件下载地址.分f ...
- SpringMVC+Ajax实现文件批量上传和下载功能实例代码
需求: 文件批量上传,支持断点续传. 文件批量下载,支持断点续传. 使用JS能够实现批量下载,能够提供接口从指定url中下载文件并保存在本地指定路径中. 服务器不需要打包. 支持大文件断点下载.比如下 ...
- 文件批量上传的工具,要实现暂停继续、断点续传等功能(使用QtNetwork和QHttpMultiPart,和定时器检查超时)
最近在做一个文件批量上传的工具,要实现暂停继续.断点续传等功能.利用Qt自带的QtNetwork模块,完成这些需求并没有费多少周章,主要思路就是将文件分块,然后用while循环依次传输.具体实现代码比 ...
- 文件批量上传-统一附件管理器-在线预览文件(有互联网和没有两种)--SNF快速开发平台3.0
实际上在SNF里使用附件管理是非常简单的事情,一句代码就可以搞定.但我也要在这里记录一下统一附件管理器能满足的需求. 通用的附件管理,不要重复开发,调用尽量简洁. 批量文件上传,并对每个文件大小限制, ...
- input file multiple 批量上传文件
这几天维护系统,有一个批量上传文件功能,出现了一点小问题 我的笔记本选择要上传的文件很正常 但在测试环境上,别人的电脑上,选择上传文件之后 一开始,以为是代码问题,网上找了很多的资料,但还是没用,然后 ...
- 利用uploadify+asp.net 实现大文件批量上传。
前言 现在网上文件上传组件随便一搜都是一大堆,不过看大家一般都在用uploadify这个来上传文件.由于项目需要,我在来试了一下.因为第一次使用,也遇到了很多问题,特此记录! ------------ ...
- uploadify文件批量上传
uploadify能够时间文件的批量上传,JS文件包下载地址,使用说明可以参考官网文档(http://www.uploadify.com/documentation/) 使用方法如下代码: $(&qu ...
随机推荐
- django模板里关闭特殊字符转换,在前端以html语法渲染
变量 pagination_html是一个方法返回的html代码,需要在前端渲染出来,不是当字符串显示 <!-- /.box-body --> {% autoescape off %} { ...
- centos6安装GitLab全程详解和常见问题解决
GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安 ...
- jenkins进阶-集成钉钉机器人(6)
最早做Jenkins发布完成以后通过邮件发送信息通知相关的联系人,发现邮件会受限于大家接收的设置,导致不能及时的看到相关的发布内容,公司使用钉钉做为公司内部的通讯工具,所以想通过Jenkins发布完成 ...
- R(4) read/write
write.table() 数据导入导出最常用的方式是使用read.table()函数和write.table()处理CSV文件的导入导出,read.table()和write.table()可以处理 ...
- protobuf 协议 windows 下 C++ 环境搭建
1. 下载protobuf https://code.google.com/p/protobuf/downloads/list Protocol Buffers 2.5.0 full source - ...
- ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded
问题: 连接Docker启动的mysql出现:ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be l ...
- RabbitMQ-1 Helloword
参考:http://rabbitmq.mr-ping.com/ 介绍 RabbitMQ是一个消息代理.它的工作就是接收和转发消息.你可以把它想像成一个邮局:你把信件放入邮箱,邮递员就会把信件投递到你的 ...
- bzoj 3795: 魏总刷DP
Description 魏总,也就是DP魏又开始刷DP了.一共有n道题,第i道题魏总原本需要u[i]秒的时间.不过,为了表达对这些水题的藐视,魏总决定先睡k秒再开始刷题.魏总并不清楚自己会睡多久,只知 ...
- Xss漏洞原理分析及简单的讲解
感觉百度百科 针对XSS的讲解,挺不错的,转载一下~ XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XS ...
- Hessian与Webservice的区别
Hessian:hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能,相比WebService,Hessian更简单.快捷. 采用的是二进制RPC协议,因为 ...