Skip to content

Commit

Permalink
Check for already-uploaded blobs via /uploads/initialize/ instead of …
Browse files Browse the repository at this point in the history
…/blobs/digest/
  • Loading branch information
jwodder committed Mar 24, 2021
1 parent 089101e commit 3fe4e9e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,24 +416,10 @@ def iter_upload(self, dandiset_id, version_id, asset_metadata, filepath):
f" {digest['value']} but is now {filetag}"
)
break
yield {"status": "initiating upload"}
lgr.debug("%s: Beginning upload", asset_path)
total_size = os.path.getsize(filepath)
try:
resp = self.post(
"/blobs/digest/",
json={"algorithm": "dandi:dandi-etag", "value": filetag},
)
except requests.HTTPError as e:
if e.response.status_code == 404:
lgr.debug("%s: Blob does not already exist on server", asset_path)
blob_exists = False
else:
raise
else:
lgr.debug("%s: Blob is already uploaded to server", asset_path)
blob_exists = True
blob_id = resp["blob_id"]
if not blob_exists:
total_size = os.path.getsize(filepath)
lgr.debug("%s: Beginning upload", asset_path)
resp = self.post(
"/uploads/initialize/",
json={
Expand All @@ -444,6 +430,13 @@ def iter_upload(self, dandiset_id, version_id, asset_metadata, filepath):
},
},
)
except requests.HTTPError as e:
if e.response.status_code == 409:
lgr.debug("%s: Blob already exists on server", asset_path)
blob_id = e.response.headers["Location"]
else:
raise
else:
upload_id = resp["upload_id"]
parts = resp["parts"]
if len(parts) != etagger.part_qty:
Expand Down

0 comments on commit 3fe4e9e

Please sign in to comment.