Class: Scholarsphere::S3::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/scholarsphere/s3/uploader.rb

Overview

Uploads a file to Scholarsphere's AWS S3 instance. When upload is invoked, a pre-signed URL is requested from Scholarsphere, and if successful, the file is then uploaded to Scholarsphere using the url.

An md5 hash is calculated for the file at initialization to ensure the file is transferred successfully.

Example

uploaded_file = Scholarsphere::S3::UploadedFile.new('path/to/file')
uploader = Scholarsphere::S3::Uploader(file: uploaded_file)
response = uploader.upload

Instance Method Summary collapse

Constructor Details

#initialize(file:) ⇒ Uploader

Returns a new instance of Uploader.

Parameters:



20
21
22
23
# File 'lib/scholarsphere/s3/uploader.rb', line 20

def initialize(file:)
  @file = file
  @content_md5 = file.content_md5
end

Instance Method Details

#uploadFaraday::Response

Returns The response from Scholarsphere to the upload request.

Returns:

  • (Faraday::Response)

    The response from Scholarsphere to the upload request.

Raises:



26
27
28
29
30
# File 'lib/scholarsphere/s3/uploader.rb', line 26

def upload
  raise Client::Error.new(request.body) unless request.success?

  request
end