Method: DropboxClient::ChunkedUploader#upload
- Defined in:
- lib/dropbox_sdk.rb
#upload(chunk_size = 4*1024*1024) ⇒ Object
Uploads data from this ChunkedUploader's file_obj in chunks, until an error occurs. Throws an exception when an error occurs, and can be called again to resume the upload.
Args:
chunk_size: The chunk size for each individual upload. Defaults to 4MB.
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/dropbox_sdk.rb', line 857 def upload(chunk_size=4*1024*1024) last_chunk = nil while @offset < @total_size if not last_chunk last_chunk = @file_obj.read(chunk_size) end resp = {} begin resp = Dropbox::parse_response(@client.partial_chunked_upload(last_chunk, @upload_id, @offset)) last_chunk = nil rescue SocketError => e raise e rescue SystemCallError => e raise e rescue DropboxError => e raise e if e.http_response.nil? or e.http_response.code[0] == '5' begin resp = JSON.parse(e.http_response.body) raise DropboxError.new('server response does not have offset key') unless resp.has_key? 'offset' rescue JSON::ParserError raise DropboxError.new("Unable to parse JSON response: #{e.http_response.body}") end end if resp.has_key? 'offset' and resp['offset'] > @offset @offset += (resp['offset'] - @offset) if resp['offset'] last_chunk = nil end @upload_id = resp['upload_id'] if resp['upload_id'] end end |