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 ...
随机推荐
- window.open 和 location.href 区别
window.open():可以在一个网站上打开另外的一个网站的地址 window.location():只能在一个网站中打开本网站的网页
- JUC线程池之 Callable和Future
Callable 和 Future 简介 Callable 和 Future 是比较有趣的一对组合.当我们需要获取线程的执行结果时,就需要用到它们.Callable用于产生结果,Future用于获取结 ...
- POJ1631 LIS模板
题目:http://poj.org/problem?id=1631 两种nlogn的方法. 1.树状数组优化暴力.有种扫描线的感觉,以时间保证位置,把值作为数组脚标. 2.记录长为...的上升子序列末 ...
- Angular 4 重定向路由
重定向路由: 用户访问一个指定的地址时,将其重新向到另一个指定的地址 (接前面的一节) 配置如下: 之前http://localhost:4200 会进入主页,现在将主页导航改为home,http:/ ...
- Asp.Net中使用Newtonsoft.Json转换,读取,写入
using Newtonsoft.Json;using Newtonsoft.Json.Converters; //把Json字符串反序列化为对象目标对象 = JsonConvert.Deserial ...
- 解决EF一对一或多对一的删除
people 类中有 zhengshu类 且是一对一,现在要删除people类中的zhengshu 网上看了N多办法,什么更新外键什么滴. 其实方法简单极了 using (KJExamEntity c ...
- Windows(x64)编译FFMPEG-2.0.1
一.引言 公司需要做网络视频传输的相关项目,初步选定用这么几个东西FFMPEG,ORTP,Live555这么几个东东.研究了也有一个月了,把一些心得写出来,这篇文章主要介绍FFMPEG在windows ...
- 编程中检查IIS7组件的安装情况
http://learn.iis.net/page.aspx/135/discover-installed-components/说明:ASP.NET网络应用程序在IIS7上部署的时候,经常会要求预装 ...
- bzoj 3768: spoj 4660 Binary palindrome二进制回文串
Description 给定k个长度不超过L的01串,求有多少长度为n的01串S满足: 1.该串是回文串 2.该串不存在两个不重叠的子串,在给定的k个串中. 即不存在a<=b<c<= ...
- elasticsearch 复杂查询小记
以下接口调用都基于5.5版本 JSON 文档格式 { "_index": "zipkin-2017-09-06", "_type": &qu ...