ruby - What is the best way to upload a file to another Rails application? -


I have researched and seen that ActiveResource is lacking in this functionality, what is the current state of the art when uploading files ?

One problem with Guillermo's perspective is that the request must be nested, such as:

  Body = {: file = & gt; {: Upload_data = & gt; File.open ("# {RAILS_ROOT} / Public / TMP /" + original_filename) ,: owner_id = & gt; Current_user.owner_id} ,: api_key = & gt; '123123123123123123'}  

Of course, it is not possible to make such a request with the HTTP client. I tried other gems found in Github (Satwar-HT-Client and Techonii-rest-customer), but they have issues in the file to be nested. Is it possible to upload files with nested requests?

You can try the following:

  # I suggested As the HTTP client gem is used (thanks!) Clnt = HTTPClient.new # The file to upload is basically with the file name 'rack maltipert 0123456789' at / tmp / # I had to rename this file, Or the resultant uploaded file will keep that filename. # Thus, I copied the file to public / TMP and changed it to my original_filname. (It will be deleted later) original_filename = params [: message] [: file] .original_filename directory = "# {RAILS_ROOT} / public / temporary" path = file. Add file (directory, original_filename) file Open (path, "w +") {| F | F.write (params [: job_application] [: restart] .read)} # I upload that file which is currently on public / TMP and then posts. Body = {: uploaded_data = & gt; File.open ("# {RAILS_ROOT} / Public / TMP /" + original_filename) ,: owner_id = & gt; Current_user.owner_id} res = clnt.post ('http: // localhost: 3000 / files.xml', body)  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -