本文介绍了使用CarrierWave将文件上传到Linode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序托管在Heroku上,我想知道是否有可能不将文件上传到Heroku上的public /文件夹,而是直接上传到-例如-Linode

My app is hosted on Heroku and I am wondering if its possible to upload a file not to the public/ folder on Heroku but directly to - say - Linode

我的应用程序同时使用Heroku和Linode。两者通过Web服务请求相互交谈。但总的来说,我尝试将所有生成/上载的文件仅存储在Linode上,而不存储在Heroku上

My app uses both Heroku and Linode. The two talk to each other via web-service requests. But generally speaking, I try to store any generated/uploaded file on Linode only - and nothing on Heroku

现在我想让用户上传文件。最终目的地是Linode。但是目前,我必须从客户端PC-> Heroku-> Linode。但是,最佳解决方案是客户端PC-> Linode

Now I have a situation where I want to allow users to upload files. The final destination would be Linode. But currently, I am having to go from Client PC -> Heroku -> Linode. The optimal solution would, however, be Client PC -> Linode

我想我会在尝试重新连接现有代码之前询问一下。
会按照以下方法更改storage_dir方法吗?

I thought I would ask before I attempt to re-wire existing code.Would changing storage_dir method as follows do the trick?

def storage_dir
  return http://<linode>/<local-folder>
end

感谢您的帮助
Abhinav

Thanks for your helpAbhinav

推荐答案

所以,您正在使用CarrierWave?我不确定您当前如何上传到Linode,但我会采取行动。

So, you're using CarrierWave? I'm not sure how you're currently uploading to Linode, but I'll take a stab.

因此,根据GitHub上CarrierWave的文档,您需要添加在您的配置/初始化程序中,可能是这样的一个载波载波。

So, according to CarrierWave's documentation on GitHub, you need to add something like this to perhaps a carrierwave.rb file in your config/initializers:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',          # required
    :aws_access_key_id      => 'xxx',          # required
    :aws_secret_access_key  => 'yyy',          # required
  }
  config.fog_directory  = 'name_of_directory'  # required
end

当然,如果您使用的是Amazon AWS S3。我在如果单击在 new(options = {})上,您会看到 @linode_api_key = options [:linode_api_key] 。因此,我认为您可以使用CarrierWave通过以下方式直接上传到Linode:

Of course, that's if you're using Amazon AWS S3. I found some fog documentation for linode (& other storage services) at http://ruby-doc.org/gems/docs/p/phpfog-fog-0.4.1.2/Fog/Linode/Compute/Mock.html If you click on 'new(options={}),' you will see @linode_api_key = options[:linode_api_key]. So, I think you'll be able to use CarrierWave to upload directly to Linode with:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'Linode',
    :linode_api_key         => 'xxx',
  }
  config.fog_directory  = 'name_of_directory'
end

这篇关于使用CarrierWave将文件上传到Linode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 11:37