httpjava文件上传原理的原理是什么?请问向qq邮箱这类可以上传文件的网页,他们上传文件的原理是不是,当用

&&&&&&&&在本地测试上传80M的文件,4秒左右就传完了,&&&上传服务器,过了几十秒都上传不上去
&&&&&&&&&&而且还出现该页无法显示了。
&&&&&&&&&&&&是什么原因????
回复讨论(解决方案)
你看下你的web.config有没有上传文件大小的限制。默认好像是10M。本地传你自己肯定快了啊。
&Web.config&我已经设置到了最大,但还是很慢啊,有什么办法,能让上传块点?
&&&上传的是视频格式的东西!&flv,mp4,mov&等!
。。。。。。
本地测试,你打开360的流量监控看看,几十M/s,当然几秒就上传了。
放在服务器,你看看,30KB/S,这能几秒就上传上去吗,至少半个小时。
出现无法显示,因为上传过期时间到了,你把过期时间再设置大一点。
Web.config&我已经设置到了最大,但还是很慢啊,有什么办法,能让上传块点?
&&上传的是视频格式的东西!&flv,mp4,mov&等!
上传大小,你是设到最大了,也要把过期时间设置大一点啊。
没有办法能它上传快,受本地网张上传影响,如果你是1M网速的,速率也不过是&200KB/S,这还是全部网络由你占有的情况下,但一般,你只能占到70到80。
&Web.config&我已经设置到了最大,但还是很慢啊,有什么办法,能让上传块点?
搞笑的,去把你的宽带换成1G的吧。
&我上传一个flv&的文件&17M&上传了4分钟左右,怎么会这么慢啊!
&&&&网速4M的&上传图片挺块的!
&我上传一个flv&的文件&17M&上传了4分钟左右,怎么会这么慢啊!
&&&&网速4M的&上传图片挺块的!
你的图片有&17M&?&80M&?
对于这样的上传,建议不要这么传统,最好将文件分块上传,设置webconfig这样的方式总是不能满足需求的
引用&7&楼&hou&的回复:
我上传一个flv&的文件&17M&上传了4分钟左右,怎么会这么慢啊!
网速4M的&上传图片挺块的!
你的图片有&17M&?&80M&?
咱能不能看好了在说,我说的是flv&文件,&&图片上传挺块的,&明白么?
是这样的,没啥好说的,上传大文件就这样,慢慢的,基于网页上传,如是容易受到影响,比如你基于网页下载大文件(右健--另存为),一开始很快,后来就慢了,因为后来人家占了资源,你就慢了,人家放了,你还是慢,就这样,没办法。
因为图片小,上传时间短,所以受影响不大,视频大,上传时间长,所以受影响大。所以,你上传视频时,最好不要乱动。
一般上传大文件我们这里都是直接通过FTP传,一是不会出现网页超时,二是稳定,三是可以续传
&难道就没别的办法了?&就只有通过FTP&上传了????
&&&&&&谁能给个办法啊!&
难道就没别的办法了?&就只有通过FTP&上传了????
&&谁能给个办法啊!
局域网上传可以达到10M/秒,但外网的上传资源份额是有限的,我们这边的电信上行就控制得很严,只有几十K/s(光纤除外),LZ可以自己找一个工具来测试一下你那边的上行流量,你就明白为什么不能通过网页上传的原因了
网上很多找下就好了。
一般上传大文件我们这里都是直接通过FTP传,一是不会出现网页超时,二是稳定,三是可以续传
FTP要服务器支持才行的吧?
&我上传一个flv&的文件&17M&上传了4分钟左右,怎么会这么慢啊!
&&&&网速4M的&上传图片挺块的!
你的浏览器是什么版本的&IE的话&有一个什么筛选的东西要关闭
关闭浏览器的smartscreen筛选试试
Web.config&我已经设置到了最大,但还是很慢啊,有什么办法,能让上传块点?
本地测试,那就是本机对本机的Http,不会有什么网络瓶颈,网速你只能去找相关的维护方了
1.&服务器上一般默认上传最大2M,在网站的配置文件里改下
2.&网页默认执行超时是90秒,在CS中加Server.ScriptTimeOut&=&3600;&单位秒
答案己出,基于网页上传就是这样,尽量在web.conging把过期时间弄长一点,设置3到5小时也是可以的
要使用多线程续传技术,http肯定会超时的。
using&System.Collections.G
using&System.T
using&System.Collections.S
using&System.N
using&System.Net.S
using&System.IO;
namespace&CompleteClient
&&&&///&&summary&
&&&&///&文件发送工作类
&&&&///&&/summary&
&&&&class&PostFile
&&&&&&&&///&&summary&
&&&&&&&&///&通过post发送指定文件的指定字段到指定的uri上
&&&&&&&&///&&/summary&
&&&&&&&&///&&param&name=&uploadfile&&上传文件路径&/param&
&&&&&&&&///&&param&name=&url&&上传的到的URi位置&/param&
&&&&&&&&///&&param&name=&offset&&当前偏移量&/param&
&&&&&&&&///&&param&name=&size&&需要发送的块大小&/param&
&&&&&&&&///&&param&name=&fileFormName&&服务器端&GET&取得的文件名&/param&
&&&&&&&&///&&param&name=&contenttype&&文件类型(保留用)&/param&
&&&&&&&&///&&param&name=&querystring&&GET数组(供服务器用GET取得一些信息)&/param&
&&&&&&&&///&&param&name=&cookies&&本地cookies(保留用)&/param&
&&&&&&&&///&&returns&uri的response的内容以string的形式返回&/returns&
&&&&&&&&public&string&UploadFileEx(string&uploadfile,&string&url,&long&offset,&long&size,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&string&fileFormName,&string&contenttype,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&NameValueCollection&querystring,&CookieContainer&cookies)
&&&&&&&&&&&&if&((fileFormName&==&null)&||
&&&&&&&&&&&&(fileFormName.Length&==&0))
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&fileFormName&=&&file&;
&&&&&&&&&&&&}
&&&&&&&&&&&&if&((contenttype&==&null)&||
&&&&&&&&&&&&(contenttype.Length&==&0))
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&contenttype&=&&application/octet-stream&;
&&&&&&&&&&&&}
&&&&&&&&&&&&string&
&&&&&&&&&&&&postdata&=&&?&;
&&&&&&&&&&&&if&(querystring&!=&null)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&foreach&(string&key&in&querystring.Keys)
&&&&&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&&&&&postdata&+=&key&+&&=&&+&querystring.Get(key)&+&&&&;
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&&&&&Uri&uri&=&new&Uri(url&+&postdata);
&&&&&&&&&&&&string&boundary&=&&----------&&+&DateTime.Now.Ticks.ToString(&x&);
&&&&&&&&&&&&HttpWebRequest&webrequest&=&(HttpWebRequest)WebRequest.Create(uri);
&&&&&&&&&&&&webrequest.CookieContainer&=&
&&&&&&&&&&&&webrequest.ContentType&=&&multipart/form-&boundary=&&+&
&&&&&&&&&&&&webrequest.Method&=&&POST&;
&&&&&&&&&&&&//&构造一个post请求的http头
&&&&&&&&&&&&StringBuilder&sb&=&new&StringBuilder();
&&&&&&&&&&&&sb.Append(&--&);
&&&&&&&&&&&&sb.Append(boundary);
&&&&&&&&&&&&sb.Append(&\r\n&);
&&&&&&&&&&&&sb.Append(&Content-Disposition:&form-&name=\&&);
&&&&&&&&&&&&sb.Append(fileFormName);
&&&&&&&&&&&&sb.Append(&\&;&filename=\&&);
&&&&&&&&&&&&sb.Append(Path.GetFileName(uploadfile));
&&&&&&&&&&&&sb.Append(&\&&);
&&&&&&&&&&&&sb.Append(&\r\n&);
&&&&&&&&&&&&sb.Append(&Content-Type:&&);
&&&&&&&&&&&&sb.Append(contenttype);
&&&&&&&&&&&&sb.Append(&\r\n&);
&&&&&&&&&&&&sb.Append(&\r\n&);
&&&&&&&&&&&&string&postHeader&=&sb.ToString();
&&&&&&&&&&&&byte[]&postHeaderBytes&=&Encoding.UTF8.GetBytes(postHeader);
&&&&&&&&&&&&//&Build&the&trailing&boundary&string&as&a&byte&array
&&&&&&&&&&&&//&ensuring&the&boundary&appears&on&a&line&by&itself
&&&&&&&&&&&&byte[]&boundaryBytes&=
&&&&&&&&&&&&Encoding.ASCII.GetBytes(&\r\n--&&+&boundary&+&&\r\n&);
&&&&&&&&&&&&FileStream&fileStream&=&new&FileStream(uploadfile,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&FileMode.Open,&FileAccess.Read);
&&&&&&&&&&&&long&length&=&postHeaderBytes.Length&+&(long)size&+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&boundaryBytes.L
&&&&&&&&&&&&webrequest.ContentLength&=&
&&&&&&&&&&&&Stream&requestStream&=&webrequest.GetRequestStream();
&&&&&&&&&&&&//&写入post头
&&&&&&&&&&&&requestStream.Write(postHeaderBytes,&0,&postHeaderBytes.Length);
&&&&&&&&&&&&//&写入文件内容
&&&&&&&&&&&&byte[]&buffer&=&new&Byte[size];
&&&&&&&&&&&&fileStream.Seek(offset,&SeekOrigin.Current);
&&&&&&&&&&&&fileStream.Read(buffer,&0,&buffer.Length);
&&&&&&&&&&&&requestStream.Write(buffer,&0,&buffer.Length);
&&&&&&&&&&&&//&写入post请求的尾
&&&&&&&&&&&&requestStream.Write(boundaryBytes,&0,&boundaryBytes.Length);
&&&&&&&&&&&&//读取服务器的反馈消息
&&&&&&&&&&&&WebResponse&responce&=&webrequest.GetResponse();
&&&&&&&&&&&&Stream&s&=&responce.GetResponseStream();
&&&&&&&&&&&&StreamReader&sr&=&new&StreamReader(s);
&&&&&&&&&&&&return&sr.ReadToEnd();
&&&&&&&&在本地测试上传80M的文件,4秒左右就传完了,&&&上传服务器,过了几十秒都上传不上去
&&&&&&&&&&而且还出现该页无法显示了。
&&&&&&&&&&&&是什么原因????
传统的HTML方式已经难已满足超大文件的上传。别说是100MB,50MB对服务器来说都是非常大的,服务不仅要专门开一个socket连接接一直等待这个文件上传完毕,还要分配同等大小的内存来保存这个文件对服务器造成的压力相当的大,而且这个压力将会随着用户的增加而成几何式的增加。就算是用Flash也不行,因为目前的Flash不支持断点续传操作,也不支持文件分块操作,Flash和传统的HTML方式上传原理一样。用Flash上传100MB图片,服务器也要分配100MB的内存。10个用户同时上传100MB数据的话,就要吃掉服务器1G的内存。
有些朋友试过用Flash文件上传控件来上传超大文件,但是经常遇到上传超时,或上传出错的问题。这是因为现在的Flash文件上传控件使用的技术还是和传统的HTML方式上传一样。没有使用分段上传技术,这种传统的HTML上传方式需要服务器必须开着一个SOCKET连接一直等到Flash上传完毕。这在大并发的情况下对服务器可能会造成非常大的压力,因为网站的访问量一大,用户上传的文件一多,服务器不可能为一个用户等很长时间。都是希望能够在最短的时间内处理完用户的请求。
像QQ邮箱中的超大附件上传功能,115网盘中的超大附件上传控件,华为网盘(DBank),金山快盘他们都是使用控件来实现超大文件上传功能的。这样做主要是减轻服务器压力,节省服务器内存,同时提高用户体验。
当然从技术角度来讲,像这些互联网知名企业也是考虑了支撑海量用户的分布式文件存储构架设计。因为他们的文件存储服务器不可能是一台,而且会动态的随着用户数的增加而增加。
如果真如某些朋友所说的Flash控件就能解决超大文件上传的问题,那么腾迅也不会花那么大的力气专门为QQ邮箱开发一个控件了。
&&&&&&&&在本地测试上传80M的文件,4秒左右就传完了,&&&上传服务器,过了几十秒都上传不上去
&&&&&&&&&&而且还出现该页无法显示了。
&&&&&&&&&&&&是什么原因????
在实际网络环境中一般100MB左右的文件都需要借助于控件来实现。一方面是因为国内的网络环境不太稳定,另一方面是从服务器的负载方面考虑。
我们的网站用户有的可能用的电信的网络,有的用的是联通的网络,有的是用的教育网,有的在南有的在北,这种复杂的网络环境导致他们访问网站的速度是不同的。有的用户网速快,比如电信的用户访问电信的机房肯定快,他上传大文件可能没有问题。但是联通的访问电信的机房可能就慢了,他上传大文件可能就出现上传超时,掉线等问题。
服务器负载的问题,现在普通的文件上传技术对服务端带来的压力还是非常大的。普通的HTML上传1G的文件,服务端需要先分配1G的内存,然后开个长连接一直等待客户上传完毕。在这个期间如果有其它的用户也要上传1G的文件,那么服务端就再分配1G的内存。可以想象如果用户多了,那服务器肯定扛不住挂扯。就算是用Flash也一样,比如swfupload还有其它的几个Flash控件,他们使用的技术还是和普通的HTML一样。
腾迅他们正是考虑了这个问题,所以使用控件来解决这个问题。他们通过控件将一个大文件,比如1G划分成许多的小块,每一小块大约是128KB,然后循环上传,直到上传完。这样做的优点就是减轻了服务端的压力,提高了服务端的负载能力,使得服务端能够处理的用户请求数多了。也节省了成本。
&&&&&&&&在本地测试上传80M的文件,4秒左右就传完了,&&&上传服务器,过了几十秒都上传不上去
&&&&&&&&&&而且还出现该页无法显示了。
&&&&&&&&&&&&是什么原因????
网上有一个Web大文件断点续传控件: /xproer/archive//2523757.html
此控件支持100G文件的断点续传操作,提供了完善的开发文档,支持文件MD5验证,支持文件批量上传。
粘贴文件,简化选择文件操作:
文件MD5值计算进度:
文件MD5值计算完毕
服务器根据MD5检测是否存在相同文件
从服务器加载文件列表
文件上传中
文件上传完毕
上传文件夹
与Discuz!X2整合-后台安装断点续传控件
与Discuz!X2整合-后台启用断点续传控件
与Discuz!X2整合-后台断点续传控件启用成功
与Discuz!X2整合-前台发帖页面
与Discuz!X2整合-上传
页面调用示例代码:
&!DOCTYPE&html&PUBLIC&&-//W3C//DTD&XHTML&1.0&Transitional//EN&&&http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&&
&html&xmlns=&http://www.w3.org/1999/xhtml&&&
&meta&http-equiv=&Content-Type&&content=&text/&charset=utf-8&&/&
&&&&&title&HTTP断点续传控件与MySQL数据库演示页面(UTF-8)&/title&
&&&&&link&href=&HttpUploader/HttpUploader.css&&type=&text/css&&rel=&Stylesheet&/&
&&&&&script&type=&text/javascript&&charset=&utf-8&&src=&HttpUploader/FileLister.js&&&/script&
&&&&&script&type=&text/javascript&&charset=&utf-8&&src=&HttpUploader/HttpUploader.js&&&/script&
&&&&&script&type=&text/javascript&&charset=&utf-8&&src=&HttpUploader/combinbox.js&&&/script&
&&&&&script&type=&text/javascript&&src=&HttpUploader/jquery-1.3.2.min.js&&&/script&
&&&&&script&language=&javascript&&type=&text/javascript&&
&&&& var&cbItemLast&=&
&&&& var&cbMgr&=&new&CombinBoxMgr();
&&&& $(document).ready(function()
cbMgr.LoadInControl(&FilePanel&);
cbMgr.Init();
&&&&&/script&
&div&id=&FilePanel&&&/div&
资源下载:
ASP.NET-ACCESS示例
ASP.NET-SQL2005示例
JSP-ACCESS-GB2312示例
JSP-ACCESS-UTF8示例
JSP-SqlServer2005-UTF8示例
JSP-MySQL-UTF8示例
PHP-MySQL-UTF8示例&&原精java Servlet上传下载文件http协议原理详解前几天要用到文件上传下载,找了找,总结一下:示例是用java&Servlet实现的,如果你有其他的需求可以加以修改,其原理是不变的。1:文件上传后台步骤:获取request当中的流信息,保存到临时文件从临时文件当中得到上传的文件名,以及文件内容,即文件内容的起始位置根据文件起始位置读取上传文件内容2:文件下载前端页面通过超链接方式发起文件下载请求,把要下载的文件名传递给后台在servlet实现文件的下载操作(设置响应类型及响应头,输出流写入文件内容)使用httpfox看上传文件的内容,为了观看方便,本地新建一个text文档使用httpfox看上传文件的内容对数据流的解释:-----------------------------69681&//对我们没用Content-Disposition: form- name=&myfile&; filename=&test&//只要使用filename=&test&这个&&里面的,也就是我们的上处的文件名,代码里使用字符串截取获得的。Content-Type: application/octet-stream//上传的类型是application/octet-stream//下面就是上传文件的具体内容了,也是我们需要存储的内容hello!haha-----------------------------69681--猜你喜欢8个牛币请下载代码后再发表评论//fileSCXZ/fileSCXZ/.settings/fileSCXZ/WebContent/fileSCXZ/WebContent/META-INF/fileSCXZ/WebContent/css/fileSCXZ/WebContent/images/fileSCXZ/WebContent/js/fileSCXZ/WebContent/jsp/fileSCXZ/build/fileSCXZ/src/fileSCXZ/src/com/fileSCXZ/src/com/shengke/fileSCXZ/src/com/shengke/servlet精精精精原精精原原精原精原相关分享原最近下载暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级最近浏览暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级扫描二维码关注最代码为好友"/>扫描二维码关注最代码为好友25184人阅读
网络编程技术(5)
平台无关语言的编程(44)
软件通用理论(37)
可参考的文章有:
/kaixuan/archive//1060284.html
在最初的&http&协议中,没有上传文件方面的功能。&rfc1867&(
)&为&http&协议添加了这个功能。客户端的浏览器,如&Microsoft&IE,&Mozila,&Opera&等,按照此规范将用户指定的文件发送到服务器。服务器端的网页程序,如&php,&asp,&jsp&等,可以按照此规范,解析出用户发送来的文件。
Microsoft&IE,&Mozila,&Opera&已经支持此协议,在网页中使用一个特殊的&form&就可以发送文件。
绝大部分&http&server&,包括&tomcat&,已经支持此协议,可接受发送来的文件。
各种网页程序,如&php,&asp,&jsp&中,对于上传文件已经做了很好的封装。
2、上传文件的实例:用&servelet&实现(http&server&为&tomcat&4.1.24)
1.&在一个&html&网页中,写一个如下的form&:
&form&enctype=&multipart/form-data&
&action=&http://192.168.29.65/UploadFile&&method=post
load&multi&files&:&br&
&input&name=&userfile1&&type=&file&
&input&name=&userfile2&&type=&file&&&br&
&input&name=&userfile3&&type=&file&&&br&
&input&name=&userfile4&&type=&file&&&br&
text&field&:&input&type=&text&&name=&text&&value=&text&&&br&
&input&type=&submit&&value=&
&&&input&type=reset&
2.&服务端&servelet&的编写
现在第三方的&http&upload&file&工具库很多。Jarkata&项目本身就提供了fileupload&包
&。文件上传、表单项处理、效率问题基本上都考虑到了。在&struts&中就使用了这个包,不过是用&struts&的方式另行封装了一次。这里我们直接使用&fileupload&包。至于struts&中的用法,请参阅&struts&相关文档。
这个处理文件上传的&servelet&主要代码如下:
public&void&doPost(&HttpServletRequest&request,&HttpServletResponse&response&)&{
DiskFileUpload&diskFileUpload&=&new&DiskFileUpload();
允许文件最大长度
diskFileUpload.setSizeMax(&100*&);
设置内存缓冲大小
diskFileUpload.setSizeThreshold(&4096&);
设置临时目录
diskFileUpload.setRepositoryPath(&&c:/tmp&&);
List&fileItems&=&diskFileUpload.parseRequest(&request&);
Iterator&iter&=&fileItems.iterator();
for(&;&iter.hasNext();&)&{
FileItem&fileItem&=&(FileItem)&iter.next();
if(&fileItem.isFormField()&)&{
&&&&&&&&&&&&
当前是一个表单项
&&&&&&&&&&&&
out.println(&&form&field&:&&&+&fileItem.getFieldName()&+&&,&&&+&fileItem.getString()&);
&&&&&&&&&&&&
当前是一个上传的文件
&&&&&&&&&&&&
String&fileName&=&fileItem.getName();
&&&&&&&&&&&&
fileItem.write(&new&File(&c:/uploads/&+fileName)&);
为简略起见,异常处理,文件重命名等细节没有写出。
3、&客户端发送内容构造
假设接受文件的网页程序位于&
假设我们要发送一个二进制文件、一个文本框表单项、一个密码框表单项。文件名为&E:/s&,其内容如下:(其中的XXX代表二进制数据,如&01&02&03)
客户端应该向
&192.168.29.65&
发送如下内容:
Accept:&text/plain,&*/*
Accept-Language:&zh-cn
Host:&192.168.29.65:80
Content-Type:multipart/form-boundary=---------------------------7d33a816d302b6
User-Agent:&Mozilla/4.0&(&OpenOffice.org)
Content-Length:&424
Connection:&Keep-Alive
-----------------------------7d33a816d302b6
Content-Disposition:&form-&name=&userfile1&;&filename=&E:/s&
Content-Type:&application/octet-stream
-----------------------------7d33a816d302b6
Content-Disposition:&form-&name=&text1&
-----------------------------7d33a816d302b6
Content-Disposition:&form-&name=&password1&
-----------------------------7d33a816d302b6--
此内容必须一字不差,包括最后的回车。
注意:Content-Length:&424&这里的424是红色内容的总长度(包括最后的回车)
注意这一行:
Content-Type:&multipart/form-&boundary=---------------------------7d33a816d302b6
根据&rfc1867,&multipart/form-data是必须的.
---------------------------7d33a816d302b6&是分隔符,分隔多个文件、表单项。其中
33a816d302b6&是即时生成的一个数字,用以确保整个分隔符不会在文件或表单项的内容中出现。前面
的&---------------------------7d&是&IE&特有的标志。&Mozila&为
---------------------------71
用手工发送这个例子,在上述的&servlet&中检验通过。
(上面有一个回车)
用户可以选择多个文件,填写表单其它项,点击&提交&按钮后就开始上传给&
&这是一个&servelet&程序
注意&enctype=&multipart/form-data&,&method=post,&type=&file&&。根
据&rfc1867,&这三个属性是必须的。multipart/form-data&是新增的编码类型,以提高二进制文件的传输效率。具体的解释请参
阅&rfc1867.
第二篇文章使用perl实现的:
/rfc1867.html
RFC1867 HTTP file upload
RFC1867 is the standard definition of that &Browse...& button that you use to upload files to
a Web server.
It introduced the INPUT field type=&file&, which is that button, and also
specified a multipart form encoding which is capable of encapsulating files for upload along
with all the other fields on an upload form.
It's not easy to find documentation on how to work with this stuff, though.
Partly this is
because if you're writing a Perl CGI it's really rather easy to work with, and partly it's due
to the fact that Microsoft IIS ASP doesn't (exactly) support RFC1867 file upload.
So on the one hand
the Unixheads think it's too trivial to document, while the ASP script kiddies
think that file upload is the exclusive preserve of genius and guru alike.
I.e. Bill doesn't think you need to use it.
If that last sounds overly bitter, it's because I just finished up a really horrible job that
involved uploading files to an IIS server.
It would have been nice had somebody at Microsoft
found file upload a sufficiently significant function to design competently.
As it is, IIS 5.0
now provides a &Request.ReadBinary& method that gives you the whole request in plaintext, and
graciously allows you to design your own object to read it.
Note that VBS has no (easy)
ability to read this binary data.
So let's assume for the time being that you're working with some reasonable non-IIS server.
do you really deal with file upload?
It turns out to be easy.
First, you design your form so that
it will actually do an upload.
In short, do this:
&form action=/mycode.cgi method=post enctype=multipart/form-data
&input type=&file&
In case you were wondering, the standard encoding type for a form is application/x-www-form-urlencoded,
and if you leave the multipart enctype out of your form, then Netscape, for one, will not upload
the file, it'll just include the filename.
If that's what you actually want, this is pretty
(However, the RFC leaves behavior in this situation undefined, so you shouldn't rely on
any particular behavior.
I haven't looked to see what IE does in this situation.
Undoubtedly
something different.)
So this much information I already knew going into my horrible project, or at least knew of it.
That's why I assumed that the server end was just as simple.
And as I mentioned, in Perl it
isn't much more difficult than retrieving normal posted data is already.
It's just that IIS
doesn't support multipart/form-data posts, that's all.
Oh, Microsoft has a solution of sorts,
called the something-or-other manager, and IIS 5.0 is so powerful that this manager thingy is
now included right in the service pack
with, gee, at least a kilobyte of documentation.
I'm off-track again, aren't I?
OK, so when this post gets to the server, what does it look like?
Well, first of all the
Content-type header of the request is set to
&&multipart/form- boundary=[some stuff]
This is how you can ascertain that you're really dealing with a properly encoded upload post.
The boundary value is probably of the form --------------------------------, where the
digits are randomly generated.
This boundary is a MIME it's guaranteed not to appear
anywhere in the data except between the multiple parts of the data.
The data itself appears in blocks that are made up of lines separated by CR/LF pairs.
like this, more or less:
-------------------------------
Content-Disposition: form- name=&nonfile_field&
value here
-------------------------------
Content-Disposition: form- name=&myfile&; filename=&ad.gif&
Content-Type: image/gif
[ooh -- file contents!]
---------------------------------
As you can see, this post isn't from the form I listed above, because I threw in a non-upload
field just to show what it looks like.
Anyway, you can see where everything is.
you get the originating local filename of the document for free in this format, meaning that
you can use this to develop a document management system.
implementation is left as an exercise for the reader.
I'll write more later on this topic,
especially if you ask me any questions.
Hint, hint.
So a Perl reader for this guy is simple: you iterate on the lines of the input and break on
your boundary.
Do things with the parts as you find them.
I have an extensive example that you can read and use,
It works (I'm using it daily) and it's well-documented.
And thus concludes the lesson for today.
Go forth and upload files.
An interesting RFC, actually, as it goes into some of the alternatives that the working group
rejected in the interest of a clean design.
My implementation in Perl.
Literately programmed.
具体协议请看:
http://tools.ietf.org/html/rfc1867
http://tools.ietf.org/html/rfc2854
http://tools.ietf.org/html/rfc2388
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1548811次
积分:18936
积分:18936
排名:第418名
原创:303篇
转载:384篇
评论:173条
(1)(2)(1)(1)(2)(25)(31)(16)(24)(3)(13)(22)(3)(9)(15)(12)(15)(29)(12)(2)(3)(11)(5)(3)(6)(7)(12)(11)(14)(27)(65)(6)(11)(7)(29)(5)(4)(2)(21)(9)(9)(14)(3)(5)(4)(5)(6)(9)(33)(5)(23)(31)(13)(3)(23)(2)(5)(2)}

我要回帖

更多关于 qq邮箱文件上传完发送 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信