Geeks With Blogs

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

Narendra Tiwari

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> Posted on Friday, January 4, 2008 11:34 AM | Back to top


Comments on this post: Using Http PUT method for file upload

# re: Using Http PUT method for file upload
Requesting Gravatar...
Am I just thick? I can't make heads or tails of that code.
Left by arg on May 14, 2008 9:53 PM

# re: Using Http PUT method for file upload
Requesting Gravatar...
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
Left by Sumit on Aug 12, 2008 4:49 AM

# re: Using Http PUT method for file upload
Requesting Gravatar...
please make smaller your post body font size, it is really really big
Left by bambino on Sep 03, 2008 7:45 PM

# re: Using Http PUT method for file upload
Requesting Gravatar...
Great explanation of PUT.

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

Thanks in advance,
Jmmm
Left by jmmm on Dec 05, 2008 3:03 AM

# re: Using Http PUT method for file upload
Requesting Gravatar...
o mshelni birat
Left by qifsha on Aug 25, 2011 8:59 PM

# Using Http PUT method for file upload
Requesting Gravatar...
Puta madre!
Left by asd on Dec 08, 2011 4:23 AM

# re: Using Http PUT method for file upload
Requesting Gravatar...
check for PUT
Left by kfkfkfk on Jun 07, 2014 12:09 PM

# re: Using Http PUT method for file upload
Requesting Gravatar...
check put
Left by prakash on Jun 07, 2014 12:10 PM

# Multiple File Upload via PUT Request
Requesting Gravatar...
Using the new Features of modern Browsers

http://rolfrost.de/mfup.html

MfG

Left by Rolf on Jul 26, 2014 1:46 AM

Your comment:
 (will show your gravatar)


Copyright © Narendra Tiwari | Powered by: GeeksWithBlogs.net | Join free