aspose file tools*
The moose likes Servlets and the fly likes file upload using doPut() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "file upload using doPut()" Watch "file upload using doPut()" New topic
Author

file upload using doPut()

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
how can we upload/FTP a file to a specified location using doPut() method?

and is it better to use doPut() method for uploading a file rather than using some utilities from apache etc?

Thanks
Neeraj
Soumil Shah
Ranch Hand

Joined: Jul 13, 2009
Posts: 54
I guess there is no method in the Servlet API to do this. And no modern browser uses HTTP PUT for anything meaningful, so doPut() should not be used [this is what my understanding]. So i guess using apache libraries could be the good. [package org.apache.commons.upload]
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

I guess there is no method in the Servlet API to do this.


There is. You can get the input stream and stream the file. The commons upload utility allows you to stream the file AND read some parameters when you do a multipart request.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
PUT is not supported by HTML forms, so if you were planning to upload files from a web browser, you can't use it.

What prompted this question? What do you hope to achieve that POST can't do?

And no modern browser uses HTTP PUT for anything meaningful

Just to be precise: HTML forms don't use PUT at all, but browsers can do useful things with PUT through the JavaScript XMLHttpRequest object.


Ping & DNS - updated with new look and Ping home screen widget
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
BTW, I think many web servers are configured not to accept PUT and DELETE Http Requests, So I think it is better to stick to POST,
If its your server and looking for good amounts of file transfers, I guess you can consider using a FTP Server/client combination instead...

HTH
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

BTW, I think many web servers are configured not to accept PUT and DELETE Http Requests


Does this claim have a source ? Most web servers should support the request, but probably, no one will every use them. Unless you are working with Atom publishing protocol or something like that.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
I think many web servers are configured not to accept PUT and DELETE Http Requests

Most web servers should support the request, but probably, no one will every use them. Unless you are working with Atom publishing protocol or something like that.

... or RESTful web services, which make extensive use of the less common HTTP methods, and are becoming ever more popular.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

I am going through a source code, where a servlet is written to process doPut Request. it is saving the file uploaded as .csv file using stream. I am not sure how that servlet is getting invoked if it can't be invoked through a browser.

can it be done through some web proxy servers by modifying the http methods?

I am not sure if it's file upload or it's supporting FTP.


Any inputs will be a great help.

Thanks
Neeraj.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Servlets do not support FTP, and proxies had better not modify any request as fundamentally as changing the method.

Even though HTML forms do not support PUT, there's no difficulty in writing a client that does - the Apache HttpClient library is an example of that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file upload using doPut()
 
Similar Threads
doPost() vs doPut()
Put and Post
PUT method is not working in Tomcat
doPut
doPut() & doDelete() in servltes