Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test file upload using HTTP PUT method

Tags:

http

put

curl

I've written a service using HTTP PUT method for uploading a file.

Web Browsers don't support PUT so I need a method for testing. It works great as a POST hitting it from a browser.

update: This is what worked. I tried Poster but it suffers from the same thing as using fiddler. You have to know how to build the request. curl takes care of the problem.

curl -X PUT "localhost:8080/urlstuffhere" -F "file=@filename" -b "JSESSIONID=cookievalue" 
like image 725
Speck Avatar asked Feb 28 '11 15:02

Speck


People also ask

Which HTTP method is used for file upload?

HTTP Request action allows you to upload files on a specified service.

WHAT IS PUT HTTP method?

The HTTP PUT request method is used to create a new resource or overwrite a representation of the target resource that is known by the client. Calling this method once is similar to calling it multiple times successively as it has the same effect. Though it is idempotent, we cannot cache its response.

Can I upload file using GET method?

One downside of GET requests is that they can only supply data in the form of parameters encoded in the URI (known as a Query String) or as cookies in the cookie request header. Therefore, GET cannot be used for uploading files or other operations that require large amounts of data to be sent to the server.


2 Answers

In my opinion the best tool for such testing is curl. Its --upload-file option uploads a file by PUT, which is exactly what you want (and it can do much more, like modifying HTTP headers, in case you need it):

curl http://myservice --upload-file file.txt 
like image 176
alienhard Avatar answered Sep 29 '22 23:09

alienhard


curl -X PUT -T "/path/to/file" "http://myputserver.com/puturl.tmp" 
like image 35
Mahdi Bashirpour Avatar answered Sep 29 '22 22:09

Mahdi Bashirpour