How to make a Multipart post request with Restclient?

Asked

Viewed 46 times

1

How do I make a Multipart post request with the Restclient library? Basically, I need

a) save photos posted via a form in a local directory. b) have access to metadata as file name, size...

As my knowledge in Ruby is still very limited, even reading the documentation I still can’t. I have seen that the Rest-client is a good option for the case. What I have understood so far is that I have to proceed more or less like this:

Import the library:

require rest-client

Create a class containing a code something like this:

response = RestClient::Request.execute(
  method: :post, url: "http://localhost:8080/upload", 
  timeout: 600, 
  payload: {
    multipart: true,
    file: File.new('/root/tmp/images, 'rb')
    }
  )

Assuming the above code is correct (suggestions?), how can I access the metadata?

  • You want to access the metadata on the receiving side of the request or the requesting side?

  • From the receiving side. Any idea?

  • You must first debug the controller action that is receiving this request, then, you check if you are getting the image there, you can do this by seeing what is in your params. After that, you can try uploading the image and see if you have all the information you have, go to the Ruby File class documentation and see how to get information. You can also look at the mini_magick Gem, it is good to access this information.

  • Thank you! I will search for those terms you quoted.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.