Class: WebpackerUploader::Providers::Aws
- Inherits:
-
Object
- Object
- WebpackerUploader::Providers::Aws
- Defined in:
- lib/webpacker_uploader/providers/aws.rb
Overview
AWS provider uploads files to AWS S3. It uses the +aws-sdk-s3+ gem.
Defined Under Namespace
Classes: CredentialsError
Instance Method Summary collapse
-
#initialize(options) ⇒ Aws
constructor
A new instance of Aws.
-
#upload!(object_key, file, content_type = "", cache_control = "")
Uploads a file to AWS S3.
Constructor Details
#initialize(options) ⇒ Aws
Note:
Any unknown options will be passed directly to the +Aws::S3::Client+ class during initialization.
Returns a new instance of Aws.
53 54 55 56 57 58 59 |
# File 'lib/webpacker_uploader/providers/aws.rb', line 53 def initialize() @region = .delete(:region) @bucket_name = .delete(:bucket) @credentials = credentials(.delete(:credentials)) @aws_options = @resource = ::Aws::S3::Resource.new(client: client) end |
Instance Method Details
#upload!(object_key, file, content_type = "", cache_control = "")
This method returns an undefined value.
Uploads a file to AWS S3.
67 68 69 70 |
# File 'lib/webpacker_uploader/providers/aws.rb', line 67 def upload!(object_key, file, content_type = "", cache_control = "") object = @resource.bucket(@bucket_name).object(object_key) object.upload_file(file, content_type: content_type, cache_control: cache_control) end |