Class: Uploadcare::Client::UploaderClient
- Inherits:
-
UploadClient
- Object
- ApiStruct::Client
- UploadClient
- Uploadcare::Client::UploaderClient
- Defined in:
- lib/uploadcare/client/uploader_client.rb
Overview
This is client for general uploads
Instance Method Summary collapse
-
#file_info(uuid) ⇒ Object
Get information about an uploaded file Secret key not needed.
-
#get_upload_from_url_status(token) ⇒ Object
Check upload status.
-
#upload(file, options = {}) ⇒ Object
syntactic sugar for upload_many There is actual upload method for one file, but it is redundant.
-
#upload_from_url(url, options = {}) ⇒ Object
Upload files from url options: - check_URL_duplicates - filename - save_URL_duplicates - async - returns upload token instead of upload data - metadata - file metadata, hash.
- #upload_many(arr, options = {}) ⇒ Object
Methods inherited from UploadClient
Methods included from Uploadcare::Concerns::ThrottleHandler
Methods included from Uploadcare::Concerns::ErrorHandler
Instance Method Details
#file_info(uuid) ⇒ Object
Get information about an uploaded file Secret key not needed
https://uploadcare.com/api-refs/upload-api/#tag/Upload/operation/fileUploadInfo
61 62 63 64 65 66 67 |
# File 'lib/uploadcare/client/uploader_client.rb', line 61 def file_info(uuid) query_params = { file_id: uuid, pub_key: Uploadcare.config.public_key } get(path: 'info/', params: query_params) end |
#get_upload_from_url_status(token) ⇒ Object
Check upload status
52 53 54 55 |
# File 'lib/uploadcare/client/uploader_client.rb', line 52 def get_upload_from_url_status(token) query_params = { token: token } get(path: 'from_url/status/', params: query_params) end |
#upload(file, options = {}) ⇒ Object
syntactic sugar for upload_many There is actual upload method for one file, but it is redundant
26 27 28 |
# File 'lib/uploadcare/client/uploader_client.rb', line 26 def upload(file, = {}) upload_many([file], ) end |
#upload_from_url(url, options = {}) ⇒ Object
Upload files from url options:
- check_URL_duplicates
- filename
- save_URL_duplicates
- async - returns upload token instead of upload data
- metadata - file metadata, hash
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/uploadcare/client/uploader_client.rb', line 38 def upload_from_url(url, = {}) body = upload_from_url_body(url, ) token_response = post(path: 'from_url/', headers: { 'Content-Type': body.content_type }, body: body) return token_response if [:async] uploaded_response = poll_upload_response(token_response.success[:token]) return uploaded_response if uploaded_response.success[:status] == 'error' Dry::Monads::Result::Success.call(files: [uploaded_response.success]) end |
#upload_many(arr, options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/uploadcare/client/uploader_client.rb', line 16 def upload_many(arr, = {}) body = upload_many_body(arr, ) post(path: 'base/', headers: { 'Content-Type': body.content_type }, body: body) end |