class Uploadcare::Client::MultipartUploaderClient
Client
for multipart uploads
Public Instance Methods
upload(object, store: false)
click to toggle source
Upload a big file by splitting it into parts and sending those parts into assigned buckets object should be File
# File lib/uploadcare/client/multipart_upload_client.rb, line 16 def upload(object, store: false) response = upload_start(object, store: store) return response unless response.success[:parts] && response.success[:uuid] links = response.success[:parts] uuid = response.success[:uuid] ChunksClient.new.upload_chunks(object, links) upload_complete(uuid) end
upload_complete(uuid)
click to toggle source
When every chunk is uploaded, ask Uploadcare
server to finish the upload
# File lib/uploadcare/client/multipart_upload_client.rb, line 37 def upload_complete(uuid) body = HTTP::FormData::Multipart.new( 'UPLOADCARE_PUB_KEY': Uploadcare.config.public_key, 'uuid': uuid ) post(path: 'multipart/complete/', body: body, headers: { 'Content-type': body.content_type }) end
upload_start(object, store: false)
click to toggle source
Asks Uploadcare
server to create a number of storage bin for uploads
# File lib/uploadcare/client/multipart_upload_client.rb, line 27 def upload_start(object, store: false) body = HTTP::FormData::Multipart.new( Param::Upload::UploadParamsGenerator.call(store).merge(multiupload_metadata(object)) ) post(path: 'multipart/start/', headers: { 'Content-type': body.content_type }, body: body) end
Private Instance Methods
multiupload_metadata(file)
click to toggle source
# File lib/uploadcare/client/multipart_upload_client.rb, line 47 def multiupload_metadata(file) file = HTTP::FormData::File.new(file) { filename: file.filename, size: file.size, content_type: file.content_type } end
post(**args)
click to toggle source
# File lib/uploadcare/client/multipart_upload_client.rb, line 57 def post(**args) handle_throttling { api_struct_post(**args) } end
Also aliased as: api_struct_post