上传1G的文件,有谁做过,请指点一下方法 上传1G的文件,有谁做过,请指点一下方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转发:这段代码测试ok我只上传过380M 1G我没试过MultiUpload.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MultiUpload.aspx.vb" Inherits="aspxWeb.MultiUpload" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>多文件上传</title> <script language="JavaScript"> function addFile() { var str = '<INPUT type="file" size="50" NAME="File">' document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str) } </script> </HEAD> <body> <form id="form1" method="post" runat="server" enctype="multipart/form-data"> <center> <asp:Label Runat="server" ID="MyTitle"></asp:Label> <P id="MyFile"><INPUT type="file" size="50" NAME="File"></P> <P> <input type="button" value="增加(Add)" onclick="addFile()"> <asp:Button Runat="server" Text="上传" ID="Upload"></asp:Button> <input onclick="this.form.reset()" type="button" value="重置(ReSet)"> </P> </center> <P align="center"> <asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt" Width="500px" BorderStyle="None" BorderColor="White"></asp:Label> </P> </form> </body></HTML>UpLoad.aspx<%@ Page language="c#" Codebehind="UpLoad.aspx.cs" AutoEventWireup="false" Inherits="WebPortal.Upload" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>多文件上传</title> <script language="JavaScript"> function addFile() { var str = '<INPUT type="file" size="50" NAME="File">' document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str) } </script> </HEAD> <body> <form id="form1" method="post" runat="server" enctype="multipart/form-data"> <div align="center"> <h3>多文件上传</h3> <P id="MyFile"><INPUT type="file" size="50" NAME="File"></P> <P> <input type="button" value="增加(Add)" onclick="addFile()"> <input onclick="this.form.reset()" type="button" value="重置(ReSet)"> <asp:Button Runat="server" Text="开始上传" ID="UploadButton"></asp:Button> </P> <P> <asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt" Width="500px" BorderStyle="None" BorderColor="White"></asp:Label> </P> </div> </form> </body></HTML>UpLoad.aspx.csusing System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace WebPortal{ /// <summary> /// UpLoad 的摘要说明。 /// 实现多文件上传 /// </summary> public class Upload : System.Web.UI.Page { protected System.Web.UI.WebControls.Button UploadButton; protected System.Web.UI.WebControls.Label strStatus; private void Page_Load(object sender, System.EventArgs e) { /// 在此处放置用户代码以初始化页面 if (this.IsPostBack) this.SaveImages(); } private Boolean SaveImages() { ///'遍历File表单元素 HttpFileCollection files = HttpContext.Current.Request.Files; /// '状态信息 System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); strMsg.Append("上传的文件分别是:<hr color=red>"); try { for(int iFile = 0; iFile < files.Count; iFile++) { ///'检查文件扩展名字 HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension; fileName = System.IO.Path.GetFileName(postedFile.FileName); if (fileName != "") { fileExtension = System.IO.Path.GetExtension(fileName); strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>"); strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>"); strMsg.Append("上传文件的文件名:" + fileName + "<br>"); strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>"); ///'可根据扩展名字的不同保存到不同的文件夹 ///注意:可能要修改你的文件夹的匿名写入权限。 postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName); } } strStatus.Text = strMsg.ToString(); return true; } catch(System.Exception Ex) { strStatus.Text = Ex.Message; return false; } }web.config: <httpRuntime executionTimeout="6000" maxRequestLength="2024000" useFullyQualifiedRedirectUrl="false"/>这句我后改的没测试过 我的思路是: 1.也算是个笨办法吧,一般不可取。在配置文件里面改结点httpruntime的大小,一个是maxRequestLength大小,然后是executeTimeout的大小。应为在web里面上传文件的大小是4兆,maxRequestLength是上传文件的大小的限制条件,executeTimeout是执行请求时间的大小限制,他们是成正比的。最好是用.net自带的压缩类把他压缩成.zip文件。 2.先获取文件的长度,然后用一个循环,每循环一次就分割一定长度的文件,用字节数组来保存。最后就上传,就这样。 很容易。你搜索一下,flash 上传,现在都流行用flash。 1,FLASH上传2,FTP上传大文件上传就这两种好点 采用flash+C#结合比较简单,不需要客户端装什么东西 在局域网上试过.自己做了个控件也支持.如果楼主你用的是ASP.NET2.0, 那么就只需要把web.config里的httpRuntime里的某个设置改一下就OK了.如果是ASP.NET1.X,那就麻烦了, ASP.NET1.X会把内存吃光的. 醉翁之意不在答问题,在于发广告也------------------------------------------------ 我们要新招一个JavaScript的开发人员哦.有人有兴趣来吗?? http://www.cnblogs.com/Lostinet/archive/2008/01/31/1059527.html 我用的是ASP.NET2.0,把web.config里的httpRuntime里的设置改一下,就不会占用内存了吗? 要用到 httpworkerrequest 自己去分析头信息你自己Google吧,网上很多 flash+asp.net上传是个不错的办法..网上搜一下.有很多. 说实话...大文件上传走http属于没事儿找事儿...ftp协议就是专门的文件传输协议...为什么不用?试想一下...1G文件上传到99%网断了用户什么表情...难道你还要想用JavaScript写断点续传? AspnetUpload_23Download单个大文件上传,支持进度条多个大文件上传,支持进度条要注意的是 web.config 的超时设置 <aspnetUploadSettings> <!-- Key Name: lisenceKey Valid Value: Purchased lisence key from the control author. --> <add key="lisenceKey" value="Lisence key purchase from www.aspnetupload.net"/> <!-- Key Name: maxRequestLength Valid Value: KBytes size of maximum upload file length to accept --> <add key="maxRequestLength" value="2048000"/> </aspnetUploadSettings>这里设置的是2G大的文件 我做过文档管理系统, 单个文件最小为几字节 最大为3G多,用的就是 AspnetUpload_23 比较不错.AspnetUpload_22版的 虽然开源码 但是错误还是有. AspnetUpload_23 比较完善. FLASH上传 我试过了,本机上传1G的文件倒是成功了,不过FLASH上传文件有个问题就是必须先调用方法弹出文件选择框后才能调用其上传的方法,也许是FLASH的安全限制? 我的目标程序是自动上传的,好像FLASH上传文件的方法不行 FTP上传 还可以,不过安全问题比较麻烦3楼的代码 我试过,不知为什么老是不行,还是谢谢11楼 的方法 我没有试过,不知道那样做会不会占用很多内存用 AspnetUpload 上传1G的文件好像要收费的还有其他的办法吗? FTP有严重的安全的问题啊~~~~ WCF上传。btyes二进制 传输 。 winform中开发控件的问题 cs文件中sql语句参数问题 求asp.net抽奖程序模块或有抽奖模块的程序 无法读到该标签,如何解决 搞了一天,没搞出来,请大家帮忙呀 从一个表中取出记录,但要从这些记录中排除另一个表中有的记录。怎么做? 多框架的跳转问题 请问我该如何在后台代码中动态修改GridView中绑定的TextBox的属性。 怎样把在Dreamweaver里画好的table放到DataGrid模板里面 怎样使用cookies对象Expired的属性 怎么让GridView和数据库绑定? 与Page_Load相反的方法是什么?
MultiUpload.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MultiUpload.aspx.vb"
Inherits="aspxWeb.MultiUpload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>多文件上传</title>
<script language="JavaScript">
function addFile()
{
var str = '<INPUT type="file" size="50" NAME="File">'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<center>
<asp:Label Runat="server" ID="MyTitle"></asp:Label>
<P id="MyFile"><INPUT type="file" size="50" NAME="File"></P>
<P>
<input type="button" value="增加(Add)" onclick="addFile()">
<asp:Button Runat="server" Text="上传" ID="Upload"></asp:Button>
<input onclick="this.form.reset()" type="button" value="重置(ReSet)">
</P>
</center>
<P align="center">
<asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True"
Font-Size="9pt" Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
</P>
</form>
</body>
</HTML>
UpLoad.aspx<%@ Page language="c#" Codebehind="UpLoad.aspx.cs" AutoEventWireup="false" Inherits="WebPortal.Upload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>多文件上传</title>
<script language="JavaScript">
function addFile()
{
var str = '<INPUT type="file" size="50" NAME="File">'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<div align="center">
<h3>多文件上传</h3>
<P id="MyFile"><INPUT type="file" size="50" NAME="File"></P>
<P>
<input type="button" value="增加(Add)" onclick="addFile()">
<input onclick="this.form.reset()" type="button" value="重置(ReSet)">
<asp:Button Runat="server" Text="开始上传" ID="UploadButton"></asp:Button>
</P>
<P>
<asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt"
Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
</P>
</div>
</form>
</body>
</HTML>
UpLoad.aspx.csusing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebPortal
{
/// <summary>
/// UpLoad 的摘要说明。
/// 实现多文件上传
/// </summary>
public class Upload : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button UploadButton;
protected System.Web.UI.WebControls.Label strStatus; private void Page_Load(object sender, System.EventArgs e)
{
/// 在此处放置用户代码以初始化页面
if (this.IsPostBack) this.SaveImages();
} private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files; /// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
}
web.config: <httpRuntime executionTimeout="6000" maxRequestLength="2024000" useFullyQualifiedRedirectUrl="false"/>这句我后改的没测试过
1.也算是个笨办法吧,一般不可取。在配置文件里面改结点httpruntime的大小,一个是maxRequestLength大小,然后是executeTimeout的大小。应为在web里面上传文件的大小是4兆,maxRequestLength是上传文件的大小的限制条件,executeTimeout是执行请求时间的大小限制,他们是成正比的。
最好是用.net自带的压缩类把他压缩成.zip文件。
2.先获取文件的长度,然后用一个循环,每循环一次就分割一定长度的文件,用字节数组来保存。最后就上传,就这样。
2,FTP上传
大文件上传就这两种好点
自己做了个控件也支持.如果楼主你用的是ASP.NET2.0, 那么就只需要把web.config里的httpRuntime里的某个设置改一下就OK了.如果是ASP.NET1.X,那就麻烦了, ASP.NET1.X会把内存吃光的.
http://www.cnblogs.com/Lostinet/archive/2008/01/31/1059527.html
你自己Google吧,网上很多
单个大文件上传,支持进度条多个大文件上传,支持进度条要注意的是 web.config 的超时设置
<aspnetUploadSettings>
<!--
Key Name: lisenceKey
Valid Value: Purchased lisence key from the control author.
-->
<add key="lisenceKey" value="Lisence key purchase from www.aspnetupload.net"/>
<!--
Key Name: maxRequestLength
Valid Value: KBytes size of maximum upload file length to accept
-->
<add key="maxRequestLength" value="2048000"/>
</aspnetUploadSettings>
这里设置的是2G大的文件
3楼的代码 我试过,不知为什么老是不行,还是谢谢11楼 的方法 我没有试过,不知道那样做会不会占用很多内存用 AspnetUpload 上传1G的文件好像要收费的还有其他的办法吗?
FTP有严重的安全的问题啊~~~~