-
-
Save BlackHacked/5b8551e9dcb9be6fac19242e7f7d2c8c to your computer and use it in GitHub Desktop.
python chunk upload files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def read_in_chunks(file_object, chunk_size=1000000): | |
while True: | |
data = file_object.read(chunk_size) | |
if not data: | |
break | |
yield data | |
def main(file): | |
content_name = str(file) | |
content_path = os.path.abspath(file) | |
content_size = os.stat(content_path).st_size | |
print(content_name, content_path, content_size) | |
f = open(content_path,"rb") | |
index = 0 | |
offset = 0 | |
headers = {} | |
for chunk in read_in_chunks(f): | |
offset = index + len(chunk) | |
headers['Content-Type'] = 'application/octet-stream' | |
headers['Content-length'] = content_size | |
headers['Content-Range'] = 'bytes %s-%s/%s' % (index, offset, content_size) | |
index = offset | |
print(len(chunk)) | |
if __name__ == '__main__': | |
file_path = r"" | |
main(file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment