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. How 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">
</form>

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 useful. (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.

Yeesh. 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-data; 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 --------------------------------1878979834, where the digits are randomly generated. This boundary is a MIME boundary; 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. It looks like this, more or less:

-------------------------------18788734234
Content-Disposition: form-data; name="nonfile_field"

value here
-------------------------------18788734234
Content-Disposition: form-data; name="myfile"; filename="ad.gif"
Content-Type: image/gif

[ooh -- file contents!]
-------------------------------18788734234--

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. Note that 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. Actual 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, which you can see here. It works (I‘m using it daily) and it‘s well-documented.

And thus concludes the lesson for today. Go forth and upload files.

http://www.vivtek.com/rfc1867.html

时间: 2024-08-04 09:30:21

RFC1867 HTTP file upload的相关文章

Form-based File Upload in HTML(RFC-1867)

1. RootViewController.m #import "RootViewController.h" #define URL @"http://localhost:8080/TestOne/upload3.jsp" @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:U

jQuery File Upload文件上传插件使用

jQuery File Upload 是一个Jquery文件上传组件,支持多文件上传.取消.删除,上传前缩略图预览.列表显示图片大小,支持上传进度条显示:支持各种动态语言开发的服务器端.官网链接:https://github.com/blueimp/jQuery-File-Upload/wiki 特点:拖放支持:上传进度条:图像预览:可定制和可扩展的:兼容任何服务器端应用平台(PHP, Python, Ruby on Rails, Java, Node.js, Go etc.). 使用方法: 1

File upload error - unable to create a temporary file

php上传图片的时候会报错: File upload error - unable to create a temporary file 文件上传错误 - 无法创建一个临时文件 你只需要打开你的php.ini文件,设置upload_tmp_dir="f:\temp"  然后重启环境就可以了,如果还不行就去看看文件夹的权限是否有权限,赋予写入权限就好了

jquery file upload 文件上传插件

1. jquery file upload 下载 jquery file upload Demo 地址:https://blueimp.github.io/jQuery-File-Upload/ jquery file upload 下载 地址:https://github.com/blueimp/jQuery-File-Upload/tags jquery file upload API 地址:https://github.com/blueimp/jQuery-File-Upload/wiki

jQuery File Upload

jQuery File Upload 需求 有这么一个需求,一个form有多个文件要上传,但又不是传统的图片批量上传那种,是类似下图这种需求,一开始是用的swfupload做的上传,但是问题是如果有多个按钮的话,就要写很多重复的代码,于为了代码的简洁所以就开始寻求其他的方法,期间试过uploadify,但是由于样式始终调不出来,最后就放弃了,直到发现这么个小巧的玩意,jQuery File Upload. 本文包含了upload的js实现,html的分析,css的实现等内容,文章末尾有git地址

记一次jquery file upload的断点续传的问题的纠结历程

相关参考:http://www.cnblogs.com/ASPNET2008/p/3360427.html 开始打算做断点续传的时候直接拷贝的这一串代码,放到我的项目里面之后Request.Files中的Filename获取到的一直是"blob", 然后我就拖啊拖了很久,后来打算放弃掉不做了,昨天测试Jquer File Upload这个上传组件的时候发现超过2G的文件死都传不上去! 1 <system.web> 2 <httpRuntime maxRequestLe

jQuery File Upload 单页面多实例的实现

jQuery File Upload 的 GitHub 地址:https://github.com/blueimp/jQuery-File-Upload 插件描述:jQuery File Upload 是一个 jQuery 图片上传组件,支持多文件上传.取消.删除,上传前缩略图预览.列表显示图片大小,支持上传进度条显示.插件基于开放的标准,如 HTML5 和 JavaScript ,不需要额外的浏览器插件(例如使用Adobe 的 Flash ),在旧版浏览器中使用 XMLHttpRequest

jquery File upload使用总结

1. jquery file upload 下载 jquery file upload Demo 地址:https://blueimp.github.io/jQuery-File-Upload/ jquery file upload 下载   地址:https://github.com/blueimp/jQuery-File-Upload/tags jquery file upload API    地址:https://github.com/blueimp/jQuery-File-Upload

Django html file upload 上传图片

html file upload 上传图片     第一步: 这是一个上传图片的按钮 <form class="form-horizontal" method="post" action="{% url 'create_article' %}" enctype="multipart/form-data"> {% csrf_token %}   <div class="form-group"