如何上传及下载大小超过100M的文件

sunli333 2006-10-30 08:34:01
如题,要能运行的源代码,分不够可再加100
...全文
6766 95 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
95 条回复
切换为时间正序
请发表友善的回复…
发表回复
rgwfeng2 2007-02-18
  • 打赏
  • 举报
回复
mark
阿良chjlcn 2007-02-04
  • 打赏
  • 举报
回复
收藏。
ddesign 2007-01-23
  • 打赏
  • 举报
回复
学习``````
sujo 2006-11-14
  • 打赏
  • 举报
回复
其实很多时候都有这种需求的。边读边写怎么做呢?
soarheaven 2006-11-11
  • 打赏
  • 举报
回复
留个记号
o07 2006-11-10
  • 打赏
  • 举报
回复
70
sunli333 2006-11-03
  • 打赏
  • 举报
回复
谢谢楼主上的yuanmu(原木) 兄弟、孟老大及各位朋友的支持,虽然没完全解决问题,但也准备结贴了
yuanmu 2006-11-02
  • 打赏
  • 举报
回复
handler 类为:
namespace CoolUpload
{
public class module : IHttpModule
{
private string path = @"d:\iis\";

public void Dispose()
{
}

public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.BeginRequest));
}

public void BeginRequest(Object sender, EventArgs e)
{
HttpApplication context = sender as HttpApplication;

if (context.Request.ContentType.ToLower().StartsWith("multipart/form-data"))
{
IServiceProvider provider = (IServiceProvider)HttpContext.Current;
HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));

if (!wr.HasEntityBody()) return;

int theOtherLength = 0;
int contentLength;
string contentType;

contentLength = Convert.ToInt32(wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
contentType = wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);

FileStream fs = null;

... ... 写文件 ....

//处理第一次读取的内容
byte[] b1 = wr.GetPreloadedEntityBody();
fs.Write(b1, 0, b1.Length);
theOtherLength = contentLength - b1.Length;

b1 = null;

int n = 65536;
int i = 0;




//读取剩余的数据,接着写文件
while (theOtherLength > 0)
{
byte[] b = new byte[n];
int readbytes;

if (theOtherLength <= n)
{
readbytes = wr.ReadEntityBody(b, theOtherLength);
}
else
{
readbytes = wr.ReadEntityBody(b, n);
}

fs.Write(b, 0, readbytes);
b = null;

theOtherLength -= readbytes;
i++;
}

fs.Close();
fs = null;
}

}

}

}
yuanmu 2006-11-02
  • 打赏
  • 举报
回复
handler 类为:
namespace CoolUpload
{
public class handler : IHttpHandler
{
private string path = @"d:\iis\";

public void ProcessRequest(HttpContext context)
{
IServiceProvider provider = (IServiceProvider)context;
HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));

if (!wr.HasEntityBody()) return;

int theOtherLength = 0;
int contentLength;
string contentType;

contentLength = Convert.ToInt32(wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
contentType = wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);

FileStream fs = null;

... ... 写文件 ....

//处理第一次读取的内容
byte[] b1 = wr.GetPreloadedEntityBody();
fs.Write(b1, 0, b1.Length);
theOtherLength = contentLength - b1.Length;

b1 = null;

int n = 65536;
int i = 0;




//读取剩余的数据,接着写文件
while (theOtherLength > 0)
{
byte[] b = new byte[n];
int readbytes;

if (theOtherLength <= n)
{
readbytes = wr.ReadEntityBody(b, theOtherLength);
}
else
{
readbytes = wr.ReadEntityBody(b, n);
}

fs.Write(b, 0, readbytes);
b = null;

theOtherLength -= readbytes;
i++;
}

fs.Close();
fs = null;

}

public bool IsReusable
{
get { return false; }
}

}

}
yuanmu 2006-11-02
  • 打赏
  • 举报
回复
有两种方法,分别使用 IHttpHandler 和 IHttpModule
最终它们又都用 HttpWorkerRequest 读字节流。

IHttpHandler 的 web.config 的配置类似

<httpHandlers>
<add verb="POST" path="uplaod.aspx" type="CoolUpload.handler,CoolUpload"/>
</httpHandlers>
----------------------------------
IHttpModule 的 web.config 的配置类似

<httpModules>
<add name="module" type="CoolUpload.module,CoolUpload" />
</httpModules>
the7thsense 2006-11-02
  • 打赏
  • 举报
回复
马你个克
jspadmin 2006-11-02
  • 打赏
  • 举报
回复
ftp
captainwh 2006-11-02
  • 打赏
  • 举报
回复
以前做过一个activex上传控件, 使用http协议, 大小无限制
xhmbldsh 2006-11-02
  • 打赏
  • 举报
回复
学习
嗷嗷叫的老马 2006-11-01
  • 打赏
  • 举报
回复
tgq1981(全娃) ( ) 信誉:100 Blog 2006-10-31 10:20:28 得分: 0



用户有病,根本不现实。
FTP上传都会存在问题。



//

那你就等到用户没病时再去接项目吧.
njrc 2006-11-01
  • 打赏
  • 举报
回复
mark
jingzhong 2006-11-01
  • 打赏
  • 举报
回复
走过路过
但绝不错过!
XStar1979 2006-11-01
  • 打赏
  • 举报
回复
http://download.pchome.net/development/activex/6853.html#

这里的一个控件估计可以满足你的需求,不过我没测试过!
掐死温柔 2006-11-01
  • 打赏
  • 举报
回复
潜力贴啊...
XStar1979 2006-11-01
  • 打赏
  • 举报
回复
这个完全是个正常的需求!

建议楼主用FTP的方式上传:
服务器端安装FTP服务器,客户端你可写个ActiveX控件,支持FTP上传功能。
这个跟普通的用FTP软件上传差不多,无非就是一个使用网页调用控件来上传,一个是专门的软件上传。
加载更多回复(75)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧