Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP PUT File Uploads

 
Abhijit Ghatnekar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2790
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to achieve using PUT that you couldn't achieve using POST?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is, although PUT theoretically has a limit on uploaded data (URL) size that POST does not.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know my PUTs from my GETs. Never mind.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic