• Post Reply Bookmark Topic Watch Topic
  • New Topic

Upload / Post files to webserver through HTTP protocol

 
dipak mehta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to upload files to webserver (Tomcat, ISS or any other ) though HTTP protocol using HttpUrlConnection.

Is it possible to upload files without having any listener script on the server ? If yes, how ?

In my case, client can have any webserver setup and its difficult ask client to install such listener script.

Is there any other alternative / workaround for this ?

- Dipak
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need some form of receiver on the web server; check out this page for some details on existing Java packages for this. Also, using HttpClient might be easier to use than HttpUrlConnection.
[ January 12, 2006: Message edited by: Ulf Dittmer ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a multi-part mime standard for uploading files via HTTP. Most web servers don't support it out of the box; you'll have to add something like the commons FileUpload package. Then your server will work with browsers that use the filename input control.

Next you have to figure out how to send the same HTTP messages with HttpUrlConnection. That will involve setting up the right headers and sending the content with a "boundary" string to tell the server when you're done. I'd put an HTTP sniffer on my machine and see what a browser sends as a reference.

I've hand-written the server end which gave me a good appreciation of the messages coming in. Let me know if that code would be of any interest.
 
dipak mehta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to upload file using HTTP "PUT" method, its not a multipart request. Use of HttpClient is fine to me. I tried to upload on tomcat server by setting headers for "PUT" request, But it gives response code "403".

In the documentation of HttpClient ( http://jakarta.apache.org/commons/httpclient/methods/put.html ), it is mentioned like...

"The PUT method is not widely supported on public servers due to security concerns and generally FTP is used to upload new and modified files to the webserver."

Is there any standard way by which this http "PUT" method can be configured correctly on any server ?

And the solution should not be specific to one server, it can be any webserver.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PUT would be RESTful for sure. You might pop over to the Servlet forum to ask about configuring your web server to allow PUT. Once you get that turned on there is a doPut method on Servlet but I've never looked into what the message format is like.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!