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


I have an application made in Ruby on Rail. To upload images from a local machine, I must post the curl request to that application. I am using a paperclip to upload an image in my ruby ​​on Rail application.

Now this curl request is working perfectly because there is no upload image for this curl request:

  curl-v-h "accept: apply / "Jason" -H "Content-Type: Application / Jason" -X PUT -d '{"User": {"first_name": "John", "Last_name": "Smith"}, "Token": "API" } 'Http: // localhost: 3000 / users / 8   

Now I want to upload an image from my local machine.

Adding "Display_photo": @ test.jpg is not working: this is what I was trying to do: ( but its not working .) < / P>

  curl -v -hf "Accept: Application / Jason" -H "Content Type: Application / Jason" -X PUT -d '{"User": {"first_name": "First name", "Last name", "Last name", "Display_photo": @ Test.jpg}, "token": "API"} 'http: // localhost: 3000 / users / 8   

The question is how to upload images / data files / videos from curl requests

Edit The book

This is my controller:

  def update = user = user.find (parameter [: id]) response_to do | Format | If the @ user.update_attributes (params [: user]) format.html {redirect_to (user,: notice = & gt; 'the user was successfully updated.')} Format.json {rendere: file = & gt; "User / JSN / Show .Jason. ARB" ,: content_type = & gt; 'Application / Jason'} and format.html {Render: Action = & gt; "Edit"} format.json {@errors_object = @user render: file = & gt; "Shared / json / errors.json.erb" ,: content_type = & gt; 'App / Jason'} End End End   

In my model:

  Class user & lt; ActiveRecord :: Base has_attached_file: display_photo ,: styles = & gt; {: Medium = & gt; "200x200 #",: thumb = & gt; "100x100 #" ,:_with_small = & gt; "24x24 #"} and    

You uploaded a file normally like this Will:

  curl -i -f fileata = @ upload_txt http: // localhost: 5000 /   

By doing this, if you respond to this rail , Then it is sent through the application / octet-stream , which can be properly controlled.

As an uploaded file, as far as I know it is not possible to do this with a JSN request:

  for start 127.0.0.1 " / "2012-07-10 09:40:59 +2002 Processing by Home Controller # Index * / * parameter: {" Filed "= & gt; # & Lt; Action Dispatches :: HTP :: Uploaded file: 0x007f82d59a3580 @boot_filename = "upload txtic", @ content_type = "app / octet-stream", @aderer = "content-disposition: form-data; name = \" file filed " "; Filename = \" upload.txt \ "\ r \ ncontent-type: application / octet-stream \ r \ n", @tempfile = # & lt; File: / var / folders / F_ ​​/ wjnrg7cd3d9f1tpy3k5fhrwm0000gn / T / RackMultipart20120710-30471-1t9abns & gt;}    

Comments