Skip to content

Commit

Permalink
Custom metadata for XML multipart uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
emilong committed Jun 26, 2024
1 parent fd6a157 commit 0dd8326
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/gcp_storage_emulator/handlers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,17 @@ def _xml_initiate_upload(request, response, storage, *args, **kwargs):
bucket_name = _extract_host_bucket(request.host)
object_id = request.path.lstrip("/")
content_type = request.headers.get("content-type")
# TODO extract metadata from the request headers

# Collect custom metadata
# https://cloud.google.com/storage/docs/metadata#custom-metadata
metadata = {}
for key, value in request.headers.items():
match = re.match(r"x-goog-meta-(?P<metadata_key>.+)", key.lower())
if match:
metadata_key = match.group("metadata_key")
metadata[metadata_key] = value
print(metadata)

try:
upload_id = storage.create_xml_multipart_upload(
bucket_name, object_id, content_type, metadata
Expand Down

0 comments on commit 0dd8326

Please sign in to comment.