Module: Platformx::S3Helpers

Defined in:
lib/platformx/aws.rb

Instance Method Summary collapse

Instance Method Details

Download from S3



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/platformx/aws.rb', line 50

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_initObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/platformx/aws.rb', line 8

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: "#{Platformx.configuration.aws_bucket}", path: "") ⇒ Object

Upload to S3



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/platformx/aws.rb', line 25

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