The PUT method not as widely used as the POST method is the more efficient way of uploading files to a server. This is because in a POST upload the files need to be combined together into a multipart message and this message has to be decoded at the server. In contrast, the PUT method allows you to simply write the contents of the file to the socket connection that is established with the server.

When using the POST method, all the files are combined together into a single multipart/form-data type object. This MIME message when transferred to the server, has to be decoded by the server side handler. The decoding process may consume significant amounts of memory and CPU cycles for very large files.
The disadvantage with the PUT method is that if you are on a shared hosting enviorenment it may not be available to you. we need to enable the PUT verb for the server extension

Enable PUT on IIS web server:-
=========================
1. Select Virtual Directory  2.=> Properties 3.=> Configuration 4.=> Under Mappigs Tab - select extension (e.g. .aspx)=> add PUT in verb list.

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request.

Sample Code:-   Following code sample will be used to test the PUT method for Uploading the file, here ASP and VBScript is used in the sample, I'm using XmlHttpRequest object for making HttpRequest and getting the HttpResponse back from the web server.
refernces:- http://upload.thinfile.com/docs/put.php

<%

 

@ language="VBScript" %>
<html>
<
head>
<title>Upload</title>

<script language="VBSCRIPT">dim strURL
Function sendit(sfileName, sType)
sData = getFileBytes(sfileName, sType)
'MsgBox(sData)
sfileName= mid(sfileName, InstrRev(sFileName,"\")+1, len(sfileName))
dim xmlhttp
set xmlhttp = Createobject("MSXML2.XMLHTTP.3.0")
'strURL = "http://localhost/TEST/" & sfileName
xmlhttp.Open "PUT", strURL, false
xmlhttp.Send sData
show.innerText=
"Status: " & xmlhttp.statusText
show1.innerText=
"Response: " & xmlhttp.responseText
set xmlhttp=Nothing
MsgBox("Done!! File Uploaded Successfully.")
End Function Function Send(sfileName, sType)
sData = getFileBytes(sfileName, sType)
'MsgBox(sData)
sfileName = mid(sfileName, InstrRev(sFileName,"\")+1, len(sfileName))
End FunctionSub showresult()
document.write
"<CENTER>Take A look!<BR/><A href=" & strURL & ">" & URL & "</a></CENTER>"
End SubFunction getFileBytes(flnm, sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="on" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="on" then
getFileBytes = objStream.Read
else
getFileBytes = objStream.ReadText
end ifobjStream.Close
Set objStream = Nothing
End Function</script>
</
head>
<
body><form name="frmUpload" action="" method="post">
<!--WIRE FRAME DESIGN START-->
<table align="center">
<tr>
<td>
<input type="FILE" id="filedata"></td>
</tr>
<tr>
<td>
<input type="Button" value="Submit" onclick="Call sendit(filedata.value, filetype.value)"></td>
</tr>
<tr>
<td>
<input type="checkBox" id="filetype" checked>Type Binary (Uncheck for Type Text)</td>
</tr>
<tr>
<td>
<input type="button" value="SHOW IT" onclick="showresult()"></td>
</tr>
<tr>
<td>
<div id="show" align="center">
</div>
</td>
</tr>
<tr>
<td>
<div id="show1" align="center">
</div>
</td>
</tr>
</table>
</form>
</
body>
</
html>

Feedback

# re: Using Http PUT method for file upload

Am I just thick? I can't make heads or tails of that code. 5/14/2008 9:53 PM | arg

# re: Using Http PUT method for file upload

I want to use HTTP POST for uploading a document to my sharepoint library. I'm having troubles doing that. Could you please redirect me to an example post for the same.

Thanks,
Sumit 8/12/2008 4:49 AM | Sumit

# re: Using Http PUT method for file upload

please make smaller your post body font size, it is really really big 9/3/2008 7:45 PM | bambino

# re: Using Http PUT method for file upload

Great explanation of PUT.

Is it possible to translate that very interesting post in PHP ????

Thanks in advance,
Jmmm 12/5/2008 3:03 AM | jmmm

# re: Using Http PUT method for file upload

o mshelni birat 8/25/2011 8:59 PM | qifsha

# Using Http PUT method for file upload

Puta madre! 12/8/2011 4:23 AM | asd

Post a comment





 

 

News

Employers
Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with MyGooglePageRank.com

Archives

Post Categories

Image Galleries

Articles & Magazines

ASP.Net 2.0 Compilation

ASP.Net, Blogs I refer...

Atlas

Dost

Drivers and Software Download

Garhwal

Travel Domain

WSS and WebParts

Syndication: