Skip to content

WIP chunk hashing on upload #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions frameioclient/lib/upload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import math
import base64
import hashlib
import requests
import traceback
import threading
import concurrent.futures

Expand All @@ -23,6 +26,11 @@ def _calculate_chunks(self, total_size, chunk_count):

return chunk_offsets

def _get_content_md5(self, data):
digest = hashlib.md5(data[:]).digest()
# print(base64.b64encode(digest).decode('utf-8'))
return base64.b64encode(digest).decode('utf-8')

def _get_session(self):
if not hasattr(thread_local, "session"):
thread_local.session = requests.Session()
Expand All @@ -35,6 +43,7 @@ def _smart_read_chunk(self, chunk_offset, is_final_chunk):
data = file.read()
else: # If it's not the final chunk, we want to ONLY read the specified chunk
data = file.read(self.chunk_size)
# self._get_content_md5(data)
return data

def _upload_chunk(self, task):
Expand All @@ -51,13 +60,19 @@ def _upload_chunk(self, task):
session = self._get_session()

chunk_data = self._smart_read_chunk(chunk_offset, is_final_chunk)
chunk_md5 = self._get_content_md5(chunk_data)

print(chunk_md5)

try:
r = session.put(url, data=chunk_data, headers={
'content-type': self.asset['filetype'],
'x-amz-acl': 'private'
'x-amz-acl': 'private',
'Content-MD5': chunk_md5
})
# print("Completed chunk, status: {}".format(r.status_code))
# 'Content-Length': str(len(chunk_data))
print("Completed chunk, status: {}".format(r.content))
print("Completed chunk, status: {}".format(r.status_code))
except Exception as e:
print(e)

Expand Down
6 changes: 3 additions & 3 deletions tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import json
import time
import socket
import platform
import mimetypes
import shutil
import requests
import platform
import mimetypes

from math import ceil
from pprint import pprint, pformat
from datetime import datetime
from pprint import pprint, pformat
from frameioclient import FrameioClient, Utils, KB, MB

token = os.getenv("FRAMEIO_TOKEN") # Your Frame.io token
Expand Down