4

I am able to upload image to RoR application(using carrierwave for image upload) through CURL request,

curl -v -H 'Content-Type: multipart/form-data' \
-H 'Accept: application/json' \
-F "photo[display_photo]=@/home/Pictures/images.jpeg" \
-F "photo[name]=Flower" http://localhost:3001/photos.json

But i wanted to modify above command as,

curl -v -H "enctype: multipart/form-data" \
-H "Accept: application/json" \
-H "Content-type: application/json" \
-d '{"photo":{ 
 "name":"Flower", 
 "display_photo":@"/home/Pictures/images.jpeg"
}}' POST http://localhost:3001/photos.json

How to achieve it!!!

goodniceweb
  • 167
  • 1
  • 10
RubyOnRails
  • 235
  • 1
  • 15
  • 1
    I guess `-F/--form ` this is what your looking for. This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. check this SO http://stackoverflow.com/questions/3007253/send-post-xml-file-using-curl-command-line – Pramod Solanky Sep 03 '14 at 06:09

1 Answers1

1

The question looks incomplete. But i guess what you are trying to achieve is somthing similar to what is asked in this question:

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

  • Note: Do remember, asking a question on stackoverflow, or any of its variants, do keep in mind another person with the same problem faced by you. So make questions as clear as possible, such that it helps you as well as others in the future. A few links before you frame a question:
Community
  • 1
  • 1
Roopesh90
  • 80
  • 1
  • 7