INNER CODE UNIT · Python
upload_to_bucket
fyoorer/ShadowClone · shadowclone.py:60
def upload_to_bucket(chunk, keep_extension=False):
chunk_hash = perform_hashing(chunk)
if db.exists(chunk_hash):
# same file already exists in bucket
#printerr("[INFO] This file is already uploaded to bucket. Skipping upload.")
return db.get(chunk_hash)
bucket_name = config.STORAGE_BUCKET
filename, ext = os.path.splitext(chunk)
f = open(chunk,'r')
contents = f.read()
if keep_extension:
upload_key = str(uuid.uuid4()) + ext
else:
upload_key = str(uuid.uuid4())