Skip to content

Commit

Permalink
Fix XML multipart upload metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
emilong committed Jun 26, 2024
1 parent 0dd8326 commit 9f46389
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/gcp_storage_emulator/handlers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,14 @@ def _xml_initiate_upload(request, response, storage, *args, **kwargs):
if match:
metadata_key = match.group("metadata_key")
metadata[metadata_key] = value
print(metadata)

file_obj = _make_object_resource(
request.base_url, bucket_name, object_id, content_type, 0
) | {"metadata": metadata}

try:
upload_id = storage.create_xml_multipart_upload(
bucket_name, object_id, content_type, metadata
bucket_name, object_id, file_obj
)

xml = """
Expand Down
17 changes: 5 additions & 12 deletions src/gcp_storage_emulator/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,15 @@ def create_resumable_upload(self, bucket_name, file_name, file_obj):
self._write_config_to_file()
return file_id

def create_xml_multipart_upload(
self, bucket_name, file_name, content_type, metadata
):
def create_xml_multipart_upload(self, bucket_name, file_name, file_obj):
"""Initiate the necessary data to support multipart XML upload
(which means the file is uploaded in parts and then assembled by the server,
not multipart JSON upload, which means it uses a single multipart HTTP request)
Arguments:
bucket_name {string} -- Name of the bucket to save to
file_name {string} -- File name used to store data
file_obj {dict} -- GCS Object resource
Raises:
NotFound: Raised when the bucket doesn't exist
Expand All @@ -249,13 +248,7 @@ def create_xml_multipart_upload(
raise NotFound

upload_id = "{}:{}:{}".format(bucket_name, file_name, datetime.datetime.now())
self.multipart[upload_id] = {
"kind": "storage#object",
"bucket_name": bucket_name,
"id": file_name,
"metadata": metadata,
"contentType": content_type,
}
self.multipart[upload_id] = file_obj
self._write_config_to_file()
return upload_id

Expand Down Expand Up @@ -305,8 +298,8 @@ def complete_multipart_upload(self, upload_id):

safe_id = self.safe_id(upload_id)

file_name = upload.get("id")
bucket_name = upload.get("bucket_name")
file_name = upload.get("name")
bucket_name = upload.get("bucket")

# Read in all the parts' data. We could do this more
# memory-efficiently and just copy part-by-part to the final
Expand Down

0 comments on commit 9f46389

Please sign in to comment.