Class: BrickFTP::RESTfulAPI::UploadFile
- Inherits:
-
Object
- Object
- BrickFTP::RESTfulAPI::UploadFile
- Includes:
- Command
- Defined in:
- lib/brick_ftp/restful_api/upload_file.rb
Overview
Overview of uploading
Uploading files using the REST API is done in 3 stages:
- Start a new upload by sending a request to REST API to indicate intent to upload a file.
- Upload the file to the URL(s) provided by the REST API, possibly in parts via multiple uploads.
- Complete the upload by notifying the REST API that the file upload has completed.
Constant Summary collapse
- CHUNK_SIZE_RANGE =
(5_242_880..5_368_709_120).freeze
Instance Method Summary collapse
-
#call(path, data, chunk_size: nil) ⇒ BrickFTP::Types::File
At this point, you are to send a PUT request to the returned upload_uri with the file data, along with the headers and parameters provided to you from BrickFTP.
Methods included from Command
Instance Method Details
#call(path, data, chunk_size: nil) ⇒ BrickFTP::Types::File
At this point, you are to send a PUT request to the returned upload_uri with the file data, along with the headers and parameters provided to you from BrickFTP.
The upload_uri link is signed by BrickFTP and must be used within 15 minutes. You will receive an HTTP 200 response with no body upon successful upload.
Should you wish to upload the file in multiple parts (required if the file size exceeds 5 GB) you will need to request an additional upload URL for the next part.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/brick_ftp/restful_api/upload_file.rb', line 37 def call(path, data, chunk_size: nil) chunk_size = adjust_chunk_size(data, chunk_size) validate_range_of_chunk_size!(chunk_size) upload = StartUpload.new(client).call(path) chunk_io = BrickFTP::Utils::ChunkIO.new(data, chunk_size: chunk_size) rest = data.size chunk_io.each do |chunk| rest -= client.upload_file(upload.http_method, upload.upload_uri, chunk) break if !chunk_size || rest <= 0 upload = ContinueUpload.new(client).call(path, ref: upload.ref, part: upload.part_number + 1) end CompleteUpload.new(client).call(path, ref: upload.ref) end |