轨道4,回形针,Amazon S3的配置亚马逊路径 [英] Rails 4, Paperclip, Amazon S3 Config Amazon Path

查看:158
本文介绍了轨道4,回形针,Amazon S3的配置亚马逊路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置它是由回形针返回时,我的目标是成功上传到亚马逊的S3服务的端点。上传和一切工作正常,但返回的URL是不正确的显示上传。

I'm trying to configure the endpoint which is returned from paperclip when my object is successfully uploaded to Amazon's S3 service. The upload and everything is working correctly, but the URL that is being returned is incorrect for displaying the upload.

目前,正在返回的URL是 http://s3.amazonaws.com/path/to/my/items (如下面的图片中看到的)。

Right now, the url that is being returned is http://s3.amazonaws.com/path/to/my/items (as seen in the picture below).

而不是 s3.amazonaws.com ,我想根本上具体到桶的位置(例如 S3-US-西1.amazonaws .COM /路径/要/我的/项

Instead of s3.amazonaws.com, I would like the root to be specific to the bucket's location (e.g. s3-us-west-1.amazonaws.com/path/to/my/items)

我应该在哪里尝试和配置不同的URL路径(从s3.amazonaws.com到别的东西)?我试图添加URL与上述路径到像我的配置文件:

Where should I try and configure a different url path (from s3.amazonaws.com to something else)? I've tried to add a url with the above path into my configuration file like:

  #Paperclip Amazon S3
  config.paperclip_defaults = {
      :storage => :s3,
      :url => "https://s3-us-west-1.amazonaws.com/",
      :s3_credentials => {
          :bucket => ENV['S3_BUCKET_NAME'],
          :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
          :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']

      }

  }

这似乎没有任何效果。请告知,我应该设置这个选项!

Which did not appear to have any effect. Please advise on where I should be setting this option!

在此先感谢!

推荐答案

如果你打算使用S3,我们发现,您必须在您的实际模型(不只是配置文件)的S3凭据。下面是我们做的:

If you're going to use S3, we've found that you have to include the S3 credentials in your actual model (not just the config files). Here's what we do:

型号

#Image Upload 
Paperclip.options[:command_path] = 'C:\RailsInstaller\ImageMagick'
has_attached_file :image,
        :styles => { :medium => "x300", :thumb => "x100" },
        :default_url => "****",
        :storage => :s3,
        :bucket => '****',
        :s3_credentials => S3_CREDENTIALS,
            :url => "/:image/:id/:style/:basename.:extension",
            :path => ":image/:id/:style/:basename.:extension"

配置/ application.rb中

  # Paperclip (for Amazon) (we use EU servers)
  config.paperclip_defaults = {
    :storage => :s3,
    :s3_host_name => 's3-eu-west-1.amazonaws.com'
  }

配置/ s3.yml

#Amazon AWS Config
development:
  access_key_id: **********
  secret_access_key: **************
  bucket: ****

production:
  access_key_id: ***********
  secret_access_key: ***********
  bucket: ****

希望这有助于?

Hope this helps?

这篇关于轨道4,回形针,Amazon S3的配置亚马逊路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆