class Flubber::AwsFileUpload
Attributes
aws_destination[R]
file_path[R]
Public Class Methods
new(file_path, aws_destination)
click to toggle source
# File lib/aws_file_upload.rb, line 14 def initialize(file_path, aws_destination) @file_path = file_path @aws_destination = aws_destination end
upload(file_path:, aws_destination:)
click to toggle source
# File lib/aws_file_upload.rb, line 10 def self.upload(file_path:, aws_destination:) new(file_path, aws_destination).upload end
Public Instance Methods
upload()
click to toggle source
# File lib/aws_file_upload.rb, line 19 def upload connection.post("/", payload) end
Private Instance Methods
api_token()
click to toggle source
# File lib/aws_file_upload.rb, line 55 def api_token @api_token ||= ApiToken.get end
app_uuid()
click to toggle source
# File lib/aws_file_upload.rb, line 59 def app_uuid @app_uuid ||= App.uuid end
connection()
click to toggle source
# File lib/aws_file_upload.rb, line 27 def connection @connection ||= Faraday.new(presigned_post["url"]) do |f| f.request :multipart f.request :url_encoded f.adapter :net_http end end
content_type()
click to toggle source
# File lib/aws_file_upload.rb, line 63 def content_type @content_type ||= begin MimeMagic.by_path(file_path).type rescue "binary/octet-stream" end end
payload()
click to toggle source
# File lib/aws_file_upload.rb, line 35 def payload @payload ||= presigned_post["fields"].merge( :file => Faraday::UploadIO.new(file_path, content_type), ) end
presigned_post()
click to toggle source
# File lib/aws_file_upload.rb, line 41 def presigned_post @presigned_post ||= JSON.parse(Faraday.post( "#{API_URL}/presigned_posts", { "app_uuid": app_uuid, "aws_directory": aws_destination, "content_type": content_type, }, { "Authorization" => "Bearer #{api_token}" } ).body) end