Curl request to upload image from local machine to ruby on rails application Curl request to upload image from local machine to ruby on rails application curl curl

Curl request to upload image from local machine to ruby on rails application


you would normally upload a file like this:

curl -i -F filedata=@upload.txt http://localhost:5000/

doing so mimics the behavior that you would have through a webbrowsers file upload.

if you look at the rails response for this, it's sent via application/octet-stream that can be handled properly as an uploaded file. as far as i know it's not possible to do this with a json request:

Started POST "/" for 127.0.0.1 at 2012-07-10 09:40:59 +0200Processing by HomeController#index as */*  Parameters: {"filedata"=>#<ActionDispatch::Http::UploadedFile:0x007f82d59a3580 @original_filename="upload.txt", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"filedata\"; filename=\"upload.txt\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/var/folders/f_/wjnrg7cd3d9f1tpy3k5fhrwm0000gn/T/RackMultipart20120710-30471-1t9abns>>}


I had the same problem and I solved it with the following, which bypass the JSON request:

curl -v -H 'Content-Type: multipart/form-data' -H 'Accept: application/json' -H 'x-api-key:myapikey' -F "user[first_name]=firstname" -F "user[last_name]=lastname" -F "user[display_photo]=@test.jpg" http://localhost:3000/users/8 


curl -v -include --form "<param>=@/<root>/image_name.png" http://<your url>**<param>**: The image parameter of the url;**<root>**: You can use pwd get image root;**<your url>**: Post url;