Skip to content
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

Support setting Content-Type when uploading a Zarr entry #2171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 13 additions & 8 deletions dandiapi/api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,20 @@ def etag_from_blob_name(self, blob_name) -> str | None:
return etag[1:-1]
return etag

def generate_presigned_put_object_url(self, blob_name: str, base64md5: str) -> str:
def generate_presigned_put_object_url(
self, blob_name: str, base64md5: str, content_type: str | None
) -> str:
params = {
'Bucket': self.bucket_name,
'Key': blob_name,
'ACL': 'bucket-owner-full-control',
'ContentMD5': base64md5,
}
if content_type is not None:
params['ContentType'] = content_type
return self.connection.meta.client.generate_presigned_url(
ClientMethod='put_object',
Params={
'Bucket': self.bucket_name,
'Key': blob_name,
'ACL': 'bucket-owner-full-control',
'ContentMD5': base64md5,
},
Params=params,
ExpiresIn=600, # TODO: proper expiration
)

Expand Down Expand Up @@ -243,7 +248,7 @@ def etag_from_blob_name(self, blob_name) -> str | None:
else:
return response.etag

def generate_presigned_put_object_url(self, blob_name: str, _: str) -> str:
def generate_presigned_put_object_url(self, blob_name: str, _: str, content_type: str) -> str:
# Note: minio-py doesn't support using Content-MD5 headers

# storage.client will generate URLs like `http://minio:9000/...` when running in
Expand Down
4 changes: 3 additions & 1 deletion dandiapi/zarr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def s3_path(self, zarr_path: str) -> str:

def generate_upload_urls(self, path_md5s: list[dict]):
return [
self.storage.generate_presigned_put_object_url(self.s3_path(o['path']), o['base64md5'])
self.storage.generate_presigned_put_object_url(
self.s3_path(o['path']), o['base64md5'], content_type=o['content_type']
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while at it, should may be path_md5s to be renamed (it is internal, should be ok AFAIK) into e.g. path_objs or path_recs to signal that it is not just a list (or mapping) of paths to md5s?

for o in path_md5s
]

Expand Down
1 change: 1 addition & 0 deletions dandiapi/zarr/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class ZarrFileCreationSerializer(serializers.Serializer):
path = serializers.CharField()
base64md5 = serializers.CharField()
content_type = serializers.CharField(allow_null=True, default=None)


class ZarrDeleteFileRequestSerializer(serializers.Serializer):
Expand Down