Class: Uploadcare::Entity::Uploader
- Defined in:
- lib/uploadcare/entity/uploader.rb
Overview
This serializer lets user upload files by various means, and usually returns an array of files
Class Method Summary collapse
-
.file_info(uuid) ⇒ Object
Get information about an uploaded file (without the secret key).
-
.get_upload_from_url_status(token) ⇒ Object
gets a status of upload from url.
-
.multipart_upload(file, options = {}, &block) ⇒ Object
upload file of size above 10mb (involves multipart upload).
-
.upload(object, options = {}) ⇒ Object
Upload file or group of files from array, File, or url.
-
.upload_file(file, options = {}) ⇒ Object
upload single file.
-
.upload_files(arr, options = {}) ⇒ Object
upload multiple files.
-
.upload_from_url(url, options = {}) ⇒ Object
upload files from url.
Class Method Details
.file_info(uuid) ⇒ Object
Get information about an uploaded file (without the secret key)
74 75 76 |
# File 'lib/uploadcare/entity/uploader.rb', line 74 def self.file_info(uuid) UploaderClient.new.file_info(uuid) end |
.get_upload_from_url_status(token) ⇒ Object
gets a status of upload from url
68 69 70 |
# File 'lib/uploadcare/entity/uploader.rb', line 68 def self.get_upload_from_url_status(token) UploaderClient.new.get_upload_from_url_status(token) end |
.multipart_upload(file, options = {}, &block) ⇒ Object
upload file of size above 10mb (involves multipart upload)
52 53 54 55 |
# File 'lib/uploadcare/entity/uploader.rb', line 52 def self.multipart_upload(file, = {}, &block) response = MultipartUploaderClient.new.upload(file, , &block) Uploadcare::Entity::File.new(response.success) end |
.upload(object, options = {}) ⇒ Object
Upload file or group of files from array, File, or url
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/uploadcare/entity/uploader.rb', line 19 def self.upload(object, = {}) if big_file?(object) multipart_upload(object, ) elsif file?(object) upload_file(object, ) elsif object.is_a?(Array) upload_files(object, ) elsif object.is_a?(String) upload_from_url(object, ) else raise ArgumentError, "Expected input to be a file/Array/URL, given: `#{object}`" end end |
.upload_file(file, options = {}) ⇒ Object
upload single file
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/uploadcare/entity/uploader.rb', line 34 def self.upload_file(file, = {}) response = UploaderClient.new.upload_many([file], ) uuid = response.success.values.first if Uploadcare.config.secret_key.nil? Uploadcare::Entity::File.new(file_info(uuid).success) else # we can get more info about the uploaded file Uploadcare::Entity::File.info(uuid) end end |
.upload_files(arr, options = {}) ⇒ Object
upload multiple files
46 47 48 49 |
# File 'lib/uploadcare/entity/uploader.rb', line 46 def self.upload_files(arr, = {}) response = UploaderClient.new.upload_many(arr, ) response.success.map { |pair| Uploadcare::Entity::File.new(uuid: pair[1], original_filename: pair[0]) } end |
.upload_from_url(url, options = {}) ⇒ Object
upload files from url
59 60 61 62 63 64 |
# File 'lib/uploadcare/entity/uploader.rb', line 59 def self.upload_from_url(url, = {}) response = UploaderClient.new.upload_from_url(url, ) return response.success[:token] unless response.success[:files] response.success[:files].map { |file_data| Uploadcare::Entity::File.new(file_data) } end |