Skip to content

Commit

Permalink
provider: update location on every chunk PATCH
Browse files Browse the repository at this point in the history
Signed-off-by: Isabella do Amaral <[email protected]>
  • Loading branch information
isinyaaa committed Aug 20, 2024
1 parent 2eb94e6 commit 9ab5537
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def chunked_upload(
"""
# Start an upload session
headers = {"Content-Type": "application/octet-stream", "Content-Length": "0"}
headers.update(self.headers)

upload_url = f"{self.prefix}://{container.upload_blob_url()}"
r = self.do_request(upload_url, "POST", headers=headers)
Expand All @@ -611,25 +612,26 @@ def chunked_upload(
start = 0
with open(blob, "rb") as fd:
for chunk in oras.utils.read_in_chunks(fd, chunk_size=chunk_size):
print("uploading chunk starting at " + str(start))

if not chunk:
break

end = start + len(chunk) - 1
content_range = "%s-%s" % (start, end)
headers = {
"Content-Range": content_range,
"Content-Length": str(len(chunk)),
"Content-Type": "application/octet-stream",
}
headers.update(self.headers)

# Important to update with auth token if acquired
# TODO call to auth here
start = end + 1
self._check_200_response(
self.do_request(session_url, "PATCH", data=chunk, headers=headers)
r := self.do_request(
session_url, "PATCH", data=chunk, headers=headers
)
)
session_url = self._get_location(r, container)
if not session_url:
raise ValueError(f"Issue retrieving session url: {r.json()}")

# Finally, issue a PUT request to close blob
session_url = oras.utils.append_url_params(
Expand Down

0 comments on commit 9ab5537

Please sign in to comment.