Created
September 5, 2014 09:33
-
-
Save clemens/f0a087d3c7229a531f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FogFile | |
| def initialize(path) | |
| @path = path | |
| end | |
| def url | |
| directory = connection.directories.new(:key => uploader.fog_directory) | |
| file = directory.files.new(:key => @path) | |
| file.url(::Fog::Time.now + uploader.fog_authenticated_url_expiration) | |
| end | |
| def connection | |
| @connection ||= CarrierWave::Storage::Fog.new(uploader).connection | |
| end | |
| def uploader | |
| @uploader ||= OpenStruct.new( | |
| :fog_authenticated_url_expiration => 600, | |
| :fog_credentials => { | |
| :provider => 'AWS', | |
| :aws_access_key_id => ENV['S3_ACCESS_KEY_ID'], | |
| :aws_secret_access_key => ENV['S3_SECRET_ACCESS_KEY'], | |
| :region => ENV['S3_REGION'] || 'eu-west-1' | |
| }, | |
| :fog_directory => ENV['S3_BUCKET_NAME'] | |
| ) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Product.all.each do |product| | |
| product.update_attributes(:remote_factsheet_url => FogFile.new("products/#{product.identifier}.pdf").url) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment