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.
我目前正在将我的项目从PHP (codeigniter)迁移到Rails3,这非常棒。但是我是一个rails/ruby新手,所以我遇到了一个我不知道如何解决的问题。
I get new stuff on my site (A) from one certain site (B). It works like this:
我在我的网站(A)从一个特定的网站(B)得到新东西。它是这样工作的:
- On site B on a page I want to submit to my site I click a button.
- 在站点B上,在我想提交给站点的页面上,我点击一个按钮。
- Site B makes a POST request to my script on site A with an identifier of that page.
- 站点B对我在站点a上的脚本发出POST请求,其中包含该页面的标识符。
- I take this ID, and make a POST request with CURL back to the site B.
- 我拿着这个ID,用CURL返回到site B。
- Site B returns me a JSON feed with links to files.
- 站点B返回一个JSON提要,其中包含指向文件的链接。
- Then I use CURL to download the files with that ID.
- 然后我使用CURL来下载具有该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.
对于步骤1和步骤2,我假设必须在某个控制器中创建POST路由和方法。但其余的我不是很清楚。
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.
此外,在php项目中,我在相同的服务器上托管文件。现在我使用heroku,所以我需要把这些文件放到S3中。
1 个解决方案
#1
1
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.
更新:再次读取Q时,我发现远程文件必须从远程位置发送到rails应用程序,而不是从用户提供的url。Carrierwave很可能还在处理这个问题,但是我在这个领域没有经验。
This is really simple with carrierwave.
这对carrierwave来说非常简单。
Once set up, carrierwave will detect wether something is either a file upload or a path to a remote file and import it.
一旦设置好,carrierwave将检测文件上传或远程文件路径,并将其导入。
<%= 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.
S3存储是本地支持的,槽型大雾,不需要设置或配置,然后在您的上传器文件中的一些行在carrierwave本身。
#1
1
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.
更新:再次读取Q时,我发现远程文件必须从远程位置发送到rails应用程序,而不是从用户提供的url。Carrierwave很可能还在处理这个问题,但是我在这个领域没有经验。
This is really simple with carrierwave.
这对carrierwave来说非常简单。
Once set up, carrierwave will detect wether something is either a file upload or a path to a remote file and import it.
一旦设置好,carrierwave将检测文件上传或远程文件路径,并将其导入。
<%= 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.
S3存储是本地支持的,槽型大雾,不需要设置或配置,然后在您的上传器文件中的一些行在carrierwave本身。