2017-07-17 38 views
0

你好我已經包含給定的代碼Amazon S3的變量軌

def store_s3(file) 
    # We create a connection with amazon S3 
    AWS.config(access_key_id: ENV['S3_ACCESS_KEY'], secret_access_key: ENV['S3_SECRET']) 
    s3 = AWS::S3.new 
    bucket = s3.buckets[ENV['S3_BUCKET_LABELS']] 
    object = bucket.objects[File.basename(file)] 
    # the file is not the content of the file is the route 
    # file_data = File.open(file, 'rb') 
    object.write(file: file) 
    # save the file and return an url to download it 
    object.url_for(:read, response_content_type: 'text/csv') 
    end 

這個代碼是在我的本地數據工作正常存儲在亞馬遜,但是當我在Heroku的服務器部署的代碼我做了變量也在服務器上。

enter image description here

有什麼,我是缺少在這裏請讓我知道問題的原因。

+0

'我too'如何使服務器上的變量? – Nithin

+1

我在任何地方都看不到'S3_BUCKET_LABELS' –

+0

檢查heroku日誌是否有確切的錯誤 –

回答

0

我沒有看到區域,在你的例子中是S3_Hostname你的區域? 爲我自己,區域就像'我們西2'。

0

如果你想設置與carrierwave和寶石霧你的S3,你可以做這樣的配置/初始化/ carrierwave.rb

CarrierWave.configure do |config| 
    config.fog_provider = 'fog/aws' 
    config.fog_directory = 'name for s3 directory' 

    config.fog_credentials = { 
    :provider => 'AWS', 
    :aws_access_key_id => 'your access key', 
    :aws_secret_access_key => 'your secret key', 
    :region => 'your region ex: eu-west-2' 
    } 
end