2017-07-17 8 views
0

こんにちは、私は与えられたコードAmazon S3のHerokuの環境レールで動作していない変数

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

上でこのようにそれを行うことができますをしていましたか? – Nithin

+1

どこでも 'S3_BUCKET_LABELS'は表示されません –

+0

正確なエラーをherokuログで確認してください –

答えて

0

私は地域を表示していません、あなたの例ではあなたの地域はS3_ホスト名ですか? 自分のために、地域は 'us-west-2'とまったく同じでした。 `私はどのようにtoo`サーバー上の変数を

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 
関連する問題