77from six import iteritems , b , wraps , MAXSIZE
88from six .moves .urllib .parse import urljoin
99import requests
10+ import hashlib
1011
1112from tusclient .exceptions import TusUploadFailed , TusCommunicationError
1213from tusclient .request import TusRequest
@@ -76,6 +77,9 @@ class Uploader(object):
7677 would be used. But you can set your own custom fingerprint module by passing it to the constructor.
7778 - log_func (<function>):
7879 A logging function to be passed diagnostic messages during file uploads
80+ - upload_checksum (bool):
81+ Whether or not to supply the Upload-Checksum header along with each
82+ chunk. Defaults to False.
7983
8084 :Constructor Args:
8185 - file_path (str)
@@ -90,13 +94,16 @@ class Uploader(object):
9094 - url_storage (Optinal [<tusclient.storage.interface.Storage>])
9195 - fingerprinter (Optional [<tusclient.fingerprint.interface.Fingerprint>])
9296 - log_func (Optional [<function>])
97+ - upload_checksum (Optional[bool])
9398 """
9499 DEFAULT_HEADERS = {"Tus-Resumable" : "1.0.0" }
95100 DEFAULT_CHUNK_SIZE = MAXSIZE
101+ CHECKSUM_ALGORITHM_PAIR = ("sha1" , hashlib .sha1 , )
96102
97103 def __init__ (self , file_path = None , file_stream = None , url = None , client = None ,
98104 chunk_size = None , metadata = None , retries = 0 , retry_delay = 30 ,
99- store_url = False , url_storage = None , fingerprinter = None , log_func = None ):
105+ store_url = False , url_storage = None , fingerprinter = None ,
106+ log_func = None , upload_checksum = False ):
100107 if file_path is None and file_stream is None :
101108 raise ValueError ("Either 'file_path' or 'file_stream' cannot be None." )
102109
@@ -122,6 +129,9 @@ def __init__(self, file_path=None, file_stream=None, url=None, client=None,
122129 self ._retried = 0
123130 self .retry_delay = retry_delay
124131 self .log_func = log_func
132+ self .upload_checksum = upload_checksum
133+ self .__checksum_algorithm_name , self .__checksum_algorithm = \
134+ self .CHECKSUM_ALGORITHM_PAIR
125135
126136 # it is important to have this as a @property so it gets
127137 # updated client headers.
@@ -142,6 +152,19 @@ def headers_as_list(self):
142152 headers = self .headers
143153 headers_list = ['{}: {}' .format (key , value ) for key , value in iteritems (headers )]
144154 return headers_list
155+
156+ @property
157+ def checksum_algorithm (self ):
158+ """The checksum algorithm to be used for the Upload-Checksum extension.
159+ """
160+ return self .__checksum_algorithm
161+
162+ @property
163+ def checksum_algorithm_name (self ):
164+ """The name of the checksum algorithm to be used for the Upload-Checksum
165+ extension.
166+ """
167+ return self .__checksum_algorithm_name
145168
146169 @_catch_requests_error
147170 def get_offset (self ):
0 commit comments