Skip to content

Commit

Permalink
fix: Deferred upload working wip
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco committed Sep 16, 2024
1 parent 0568eda commit 95d577f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions storage3/_async/resumable.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,9 @@ async def create_unique_link(
if objectname is None and filename is None:
raise StorageException("Must specify objectname or filename")

file = None
file = filename if filename else objectname
upload_mode = None

if filename:
_, file = os.path.split(filename)
else:
file = objectname

info = FileInfo(
name=file, link="", length="", headers={"Tus-Resumable": "1.0.0"}
)
Expand All @@ -93,7 +88,8 @@ async def create_unique_link(
info["headers"][upload_mode] = size
info["length"] = size

metadata = UploadMetadata(bucketName=bucketname, objectName=file)
obj_name = os.path.split(file)[1]
metadata = UploadMetadata(bucketName=bucketname, objectName=obj_name)

info["headers"]["Upload-Metadata"] = self._encode(metadata)
response = await self._client.post(self.url, headers=info["headers"])
Expand Down Expand Up @@ -161,7 +157,7 @@ async def upload(
"Upload-Defer mode requires a link and objectname"
)

target_file = objectname if upload_defer else os.path.split(filename)[1]
target_file = objectname if upload_defer else filename
chunk_size = 1048576 * int(abs(mb_size)) # 1024 * 1024 * mb_size
size = None
self._filestore.update_file_headers(
Expand All @@ -176,6 +172,10 @@ async def upload(
raise StorageException(f"Cannot upload an empty file: {filename}")

self._filestore.update_file_headers(target_file, "Upload-Length", size)
self._filestore.update_file_headers(target_file, "Upload-Offset", "0")
headers = self._filestore.get_file_headers(target_file)
response = await self._client.patch(storage_link, headers=headers)
self._filestore.delete_file_headers(target_file, "Upload-Length")

while True:
headers = self._filestore.get_file_headers(target_file)
Expand Down

0 comments on commit 95d577f

Please sign in to comment.