module Platformx module S3Helpers ######################################################## # # Set Up Connection # ######################################################## 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 ######################################################## # # Upload to S3 # ######################################################## def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "") ################# Init S3 ################# connection = x_s3_init ################# Set Bucket ################# 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 ######################################################## # # Download from S3 # ######################################################## 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 ######################################################## # # End # ######################################################## end end