module Platformx::S3Helpers
Amazon S3 helpers
@author Tim Mushen
Public Instance Methods
x_s3_get_link(key: "", bucket: "", bucket_path: "", verbose: false)
click to toggle source
Download link from S3 asset
@param key [String] key or the file name @param bucket [String] the bucket name @param bucket_path [String] the bucket path @param verbose [Boolean] make operation verborse
@return [String] a public URL for the file
@note The returned public URL will expire in 7 days
# File lib/platformx/aws.rb, line 56 def x_s3_get_link(key: "", bucket: "", bucket_path: "", verbose: false) connection = x_s3_init expiry = Time.now.to_i + 604800 connection.directories.new(:key => "#{bucket}").files.new(:key => "#{bucket_path}/#{key}").url(expiry) if verbose == true # returns more information about file from s3 # directory = connection.directories.get("files.myclocktower.com") # file = directory.files.get("support/#{support_id}/#{key}") #return file.url(expiry) end end
x_s3_init()
click to toggle source
Set up Amazon S3 connection
@return [Fog::Storage] S3 storage connection
# File lib/platformx/aws.rb, line 13 def x_s3_init() connection = Fog::Storage.new({ :provider => 'AWS', :region => Platformx.configuration.aws_region, :aws_access_key_id => Platformx.configuration.aws_access_key_id, :aws_secret_access_key => Platformx.configuration.aws_secret_access_key }) return connection end
x_s3_upload(new_filename: "", file: "", bucket: "
click to toggle source
Upload file to S3 with the given parameters
@param new_filename [String] new name of the file @param file [String] file to be uploaded @param bucket [String] bucket to upload the file to @param path [String] path of the final file
@return S3 bucket file
# File lib/platformx/aws.rb, line 31 def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "") # Obtaining an S3 connection connection = x_s3_init # Creating the directory to upload the file to bucket = connection.directories.create(key: "#{bucket}/#{path}", public: false) # upload that resume file = bucket.files.create( :key => "#{new_filename}", :body => open(file), :public => false ) end