module Platformx::S3Helpers

Amazon S3 helpers

@author Tim Mushen

Public Instance Methods

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