#NEWLINE# @ plug . handler ( ) #NEWLINE# def upload_chunk( metadata , offset , chunk ) : #NEWLINE# #INDENT# filename = get_dropbox_filename ( metadata ) #NEWLINE# up_id = metadata . extra . get ( 'upload_id' , None ) #NEWLINE# plug . logger . debug ( 'Uploading chunk of size {} to file {} at offset {} - Upload ID: {}' . format ( len ( chunk ) , filename , offset , up_id ) ) #NEWLINE# try : #NEWLINE# #INDENT# ( _ , up_id ) = dropbox_client . upload_chunk ( file_obj = chunk , length = len ( chunk ) , offset = offset , upload_id = up_id ) #NEWLINE# #UNINDENT# except ( dropbox . rest . ErrorResponse , dropbox . rest . RESTSocketError ) as err : #NEWLINE# #INDENT# raise ServiceError ( 'Unable to upload chunk of {}: {}' . format ( filename , err ) ) #NEWLINE# #UNINDENT# if ( metadata . extra . get ( 'upload_id' , None ) != up_id ) : #NEWLINE# #INDENT# metadata . extra [ 'upload_id' ] = up_id #NEWLINE# metadata . write ( ) #NEWLINE# plug . logger . debug ( 'Storing upload ID {} in metadata' . format ( up_id ) ) #NEWLINE# #UNINDENT# plug . logger . debug ( 'Uploading chunk of size {} to file {} at offset {} - Done' . format ( len ( chunk ) , filename , offset ) )