I have this sample request with cUrl in the contract (the contract docs only show this for the endpoints):
curl
-X PUT
-H 'Content-Type: application/octet-stream'
-H 'Content-Disposition: attachment; filename=file.pdf
--upload-file my-file
https://storage.google.apis.com/…..
The endpoints intended to update an image. I have only an image in the base64
string format, and I want to upload this data through this endpoint.
- Since the API docs only provide that information, should I directly pass the
base64
string as the request body as below:
const dummyBase64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABjElEQVRIS+2VvUoDQRSGv9V2'
fetch(
'https://storage.google.apis.com/…',
{
method: 'PUT',
headers: {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename="dummy.js"'
},
body: dummyBase64Image,
}
)..... // callback handling
Or should I parse the image with the base64
string format into another form (such as parse the base64 string into binary format)?
- Is the request sample with cUrl and
content-type: application/octet-stream
in the documentation enough to conclude that the request body form must be mere abase64
string format (fetch chaining shown above)and not like the usual object that is being passed in the request body with some predetermined field name such as (below fetch chaining):
fetch(
'https://storage.google.apis.com/…',
{
method: 'PUT',
headers: {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename="dummy.js"',
},
body: {
image: dummyBase64Image,
}
}
)..... // callback handling