bassneck
bassneck

Reputation: 4043

Rails3 - download file from remote server and upload it to S3

I'm currently migrating my project from PHP (codeigniter) to Rails3 and it's amazing. But I'm a rails/ruby newbie so I've faced a problem which I don't know how to solve.

I get new stuff on my site (A) from one certain site (B). It works like this:

  1. On site B on a page I want to submit to my site I click a button.
  2. Site B makes a POST request to my script on site A with an identifier of that page.
  3. I take this ID, and make a POST request with CURL back to the site B.
  4. Site B returns me a JSON feed with links to files.
  5. Then I use CURL to download the files with that ID.

Sorry if the explanation is a bit cluttered.

For steps 1 and 2 I assume, I have to make a POST route and a method in some controller. But the rest isn't that clear to me.

Additionally, in php project I hosted files on the same servers. And now I use heroku, so I need to put those files to S3.

Upvotes: 0

Views: 1009

Answers (1)

berkes
berkes

Reputation: 27603

update: On reading the Q again, I see that the remote files must be posted from a remote location into the rails app, not from a user-provided url. Carrierwave can most probably still deal with this, but I have no experience in this particular area.

This is really simple with carrierwave.

Once set up, carrierwave will detect wether something is either a file upload or a path to a remote file and import it.

<%= form_for @user, :html => {:multipart => true} do |f| %>
  <p>
    <label>My Avatar URL:</label>
    <%= image_tag(@user.avatar_url) if @user.avatar? %>
    <%= f.text_field :remote_avatar_url %>
  </p>
<% end %>

S3 storage is supported natively, trough fog, wich needs no set-up or configuration other then a few lines in your uploader file in carrierwave itself.

Upvotes: 1

Related Questions