[GH-ISSUE #422] Correct way to call multi-part request #84

Closed
opened 2026-03-03 12:08:08 +03:00 by kerem · 4 comments
Owner

Originally created by @nhatmvo on GitHub (Feb 15, 2021).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/422

I use postman to test the gcs and this is my curl:
curl --location --request POST 'https://localhost:4443/upload/storage/v1/b/sample-bucket/o?uploadType=multipart&name=readme.txt' \ --header 'Content-Type: multipart/form-data' \ --form 'file=@"<FileLocation>"'

The content of my file is: Sample text
and the response keep telling me that:

invalid character 'S' looking for beginning of value

So, what is the correct way to send multi-part request into your gcs-server? I tried uploadType=media and it works perfectly fine

Originally created by @nhatmvo on GitHub (Feb 15, 2021). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/422 I use postman to test the gcs and this is my curl: `curl --location --request POST 'https://localhost:4443/upload/storage/v1/b/sample-bucket/o?uploadType=multipart&name=readme.txt' \ --header 'Content-Type: multipart/form-data' \ --form 'file=@"<FileLocation>"'` The content of my file is: `Sample text` and the response keep telling me that: > invalid character 'S' looking for beginning of value So, what is the correct way to send multi-part request into your gcs-server? I tried uploadType=media and it works perfectly fine
kerem 2026-03-03 12:08:08 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@fsouza commented on GitHub (Feb 15, 2021):

Google Cloud Storage doesn't support form-data. The emulator matches the GCS API. This page should have more information: https://cloud.google.com/storage/docs/uploading-objects#rest-upload-objects

<!-- gh-comment-id:778929069 --> @fsouza commented on GitHub (Feb 15, 2021): Google Cloud Storage doesn't support `form-data`. The emulator matches the GCS API. This page should have more information: https://cloud.google.com/storage/docs/uploading-objects#rest-upload-objects
Author
Owner

@nhatmvo commented on GitHub (Feb 15, 2021):

Hi @fsouza, thank you so much for a quick reply.
Anyway, I changed the Content-Type into another value, and my request is:

curl --location --request POST 'https://localhost:4443/upload/storage/v1/b/sample-bucket/o?uploadType=multipart&name=readme.txt' \ --header 'Content-Type: text/plain;boundary=test' \ --data-binary '<FileLocation>'

but I get this error:

multipart: NextPart: EOF

I'm wondering what's wrong with my request this time :(
Thank you!

<!-- gh-comment-id:778932492 --> @nhatmvo commented on GitHub (Feb 15, 2021): Hi @fsouza, thank you so much for a quick reply. Anyway, I changed the Content-Type into another value, and my request is: `curl --location --request POST 'https://localhost:4443/upload/storage/v1/b/sample-bucket/o?uploadType=multipart&name=readme.txt' \ --header 'Content-Type: text/plain;boundary=test' \ --data-binary '<FileLocation>'` but I get this error: > multipart: NextPart: EOF I'm wondering what's wrong with my request this time :( Thank you!
Author
Owner

@fsouza commented on GitHub (Feb 15, 2021):

The body must contain metadata in json format separated by the boundary: https://cloud.google.com/storage/docs/uploading-objects#single-request-upload-that-includes-object-metadata (this link will let you fill-in the data)

So in your case your file would need to have content that looks something like this (untested):

--test
Content-Type: application/json; charset=UTF-8

{"name":"readme.txt","metadata":{"key1":"value1"}}

--test
Content-Type: text/plain; charset=UTF-8

Sample text
--test--
<!-- gh-comment-id:778936276 --> @fsouza commented on GitHub (Feb 15, 2021): The body must contain metadata in json format separated by the boundary: https://cloud.google.com/storage/docs/uploading-objects#single-request-upload-that-includes-object-metadata (this link will let you fill-in the data) So in your case your file would need to have content that looks something like this (untested): ``` --test Content-Type: application/json; charset=UTF-8 {"name":"readme.txt","metadata":{"key1":"value1"}} --test Content-Type: text/plain; charset=UTF-8 Sample text --test-- ```
Author
Owner

@nhatmvo commented on GitHub (Feb 15, 2021):

Thank you so much!

<!-- gh-comment-id:778973964 --> @nhatmvo commented on GitHub (Feb 15, 2021): Thank you so much!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#84
No description provided.