Skip to content

Commit

Permalink
Use query parameter to override name from metadata (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
oittaa authored Feb 17, 2022
1 parent c1cbea0 commit afb716f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gcp_storage_emulator/handlers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,14 @@ def _make_object_resource(


def _multipart_upload(request, response, storage):
object_id = request.data["meta"].get("name")
# Overrides the object metadata's name value, if any.
if "name" in request.query:
object_id = request.query["name"][0]
obj = _make_object_resource(
request.base_url,
request.params["bucket_name"],
request.data["meta"]["name"],
object_id,
request.data["content-type"],
str(len(request.data["content"])),
request.data["meta"],
Expand All @@ -168,7 +172,7 @@ def _multipart_upload(request, response, storage):
obj = _checksums(request.data["content"], obj)
storage.create_file(
request.params["bucket_name"],
request.data["meta"]["name"],
object_id,
request.data["content"],
obj,
)
Expand All @@ -181,21 +185,25 @@ def _multipart_upload(request, response, storage):


def _create_resumable_upload(request, response, storage):
object_id = request.data.get("name")
# Overrides the object metadata's name value, if any.
if "name" in request.query:
object_id = request.query["name"][0]
content_type = request.get_header(
"x-upload-content-type", "application/octet-stream"
)
content_length = request.get_header("x-upload-content-length", None)
obj = _make_object_resource(
request.base_url,
request.params["bucket_name"],
request.data["name"],
object_id,
content_type,
content_length,
)
try:
id = storage.create_resumable_upload(
request.params["bucket_name"],
request.data["name"],
object_id,
obj,
)
encoded_id = urllib.parse.urlencode(
Expand Down

0 comments on commit afb716f

Please sign in to comment.