wood burning stoves 2.0*
The moose likes Servlets and the fly likes HTTP PUT File Uploads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP PUT File Uploads" Watch "HTTP PUT File Uploads" New topic
Author

HTTP PUT File Uploads

Abhijit Ghatnekar
Greenhorn

Joined: Nov 10, 2007
Posts: 19
Hello All,

I have written code in the past in 3 non-Java scripting languages - PHP, Perl and Python that deals with uploading a file (to a server) through PUT method. I was wondering if it is possible in Java. I'm also confused with the subtleties of the doPut() method. Could it be put to some use here?

Thank you all for your replies.

Regards,
Abhijit.


[Programmed in 4 languages ; Still In Love with Java ]
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
What are you trying to achieve using PUT that you couldn't achieve using POST?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15956
    
  19

Yes it is, although PUT theoretically has a limit on uploaded data (URL) size that POST does not.


Customer surveys are for companies who didn't pay proper attention to begin with.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Tim Holloway wrote:Yes it is, although PUT theoretically has a limit on uploaded data (URL) size that POST does not.


Wha??? Where do you find that documented. Perhaps you meant that the URL size limits the description of the resource location. PUT contents are in the body of the request and are thus not limited by the URL.

Wikipedia HTTP methods PUT

You can certainly use PUT but you can't generate a PUT from a HTML form, you would have to write your own client. You might look at the Jersey toolkit.

Bill
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15956
    
  19

Ok, William, you've got me.

The problem with PUT is that some servers had a limited-size buffer to catch the URL in - usually somewhere between 1025 and 4096 characters. So a file embedded in the URL would have to be small enough that the total URL wouldn't give the server indigestion.

You can certainly generate PUT requests from an HTML form. People have been doing it since Day 1. Just specify "method=PUT" on the form element.

However, all of the above is predicated on a straightforward PUT. If the payload file was embedded in a cookie or other request header, then that could change things. But to set up a PUT that did that would DEFINITELY require a custom client.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

Tim Holloway wrote:The problem with PUT is that some servers had a limited-size buffer to catch the URL in - usually somewhere between 1025 and 4096 characters. So a file embedded in the URL would have to be small enough that the total URL wouldn't give the server indigestion.

The payload in a PUT is in the request body so URL length restrictions are not a problem.

You can certainly generate PUT requests from an HTML form. People have been doing it since Day 1. Just specify "method=PUT" on the form element.

HTML forms do not support PUT. You can specify PUT as the form method but the browser will issue a GET.

To generate a PUT from the browsers, you can do so with an Ajax request (at least in modern browsers -- older browsers also changed PUT to GET in Ajax requests).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15956
    
  19

I don't know my PUTs from my GETs. Never mind.
 
Consider Paul's rocket mass heater.
 
subject: HTTP PUT File Uploads
 
Similar Threads
Method Vs Function
How to restrict execution of same class from two different consoles at same time?
How Much Is Java Really Being Used On The Web?
How to get local pc file from website?
struts2 i18n - default language