Class: Redox::FileUpload
- Inherits:
-
Object
- Object
- Redox::FileUpload
- Defined in:
- lib/redox/file_upload.rb
Constant Summary collapse
- ENDPOINT =
"https://blob.redoxengine.com/upload"
Instance Method Summary collapse
-
#initialize(filename_or_io, content_type, upload_as_filename = nil) ⇒ FileUpload
constructor
Create a multipart file upload.
-
#perform(source) ⇒ Object
Upload the file.
Constructor Details
#initialize(filename_or_io, content_type, upload_as_filename = nil) ⇒ FileUpload
Create a multipart file upload.
or an open IO object
13 14 15 |
# File 'lib/redox/file_upload.rb', line 13 def initialize(filename_or_io, content_type, upload_as_filename = nil) @file_part = Faraday::FilePart.new(filename_or_io, content_type, upload_as_filename) end |
Instance Method Details
#perform(source) ⇒ Object
Upload the file.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/redox/file_upload.rb', line 20 def perform(source) source.ensure_access_token connection = Faraday.new { |f| f. :Bearer, source.access_token f.request :multipart f.headers[:accept] = "application/json" } res = connection.post ENDPOINT, {file: @file_part} raise Redox::Error.new(status: res.status, body: res.body) unless res.success? uri = begin JSON.parse(res.body)["URI"] rescue end raise Redox::Error.new(status: res.status, body: res.body) unless uri uri end |