开发者

A file uploaded with HTTP PUT has extra data at the beginning and the end

开发者 https://www.devze.com 2023-01-08 15:40 出处:网络
I need to implement uploading and downloading files as cheap as possible. For my tests I use Windows XP with IIS 5 and a con开发者_开发问答sole C# program.

I need to implement uploading and downloading files as cheap as possible. For my tests I use Windows XP with IIS 5 and a con开发者_开发问答sole C# program.

I created a virtual directory in IIS and in my program I execute the following code:

System.Net.WebClient webClient = new System.Net.WebClient();
webClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
webClient.UploadFile( "http://localhost/Exchange/file.jpg", "PUT", localPathToMyFile );

those lines execute successfully and a file appears in the directory used to serve contents to the virtual directory. The problem is the file contents in surrounded by extra data:

-----------------------8ccfabf2a995855
Content-Disposition: form-data; name="file"; filename="file.jpg"
Content-Type: application/octet-stream
//file contents goes here
-----------------------8ccfabf2a995855

Where does this extra data come from? What do I do so that it doesn't appear, but the file is uploaded as is?


The extra data comes from the HTTP protocol, see here. Try changing the method to "POST" and create aa simple ASP.net webpage that receives and saves the file. Like the example here


It's how HTML forms are uploaded.

Explanation: http://www.15seconds.com/issue/001003.htm

Actual specification http://www.faqs.org/rfcs/rfc2388.html

How do you save the files?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号