Custom google storage API header on node.js
I am using googleapis.auth.JWT
for authentication and request
multi-page upload to upload JSON files to google storage, it works as expected.
Here is the code:
var data = JSON.stringify(json);
var metadata = {
name: "name"
contentLanguage: "en",
acl: [...]
};
authClient.authorize(function(err, tokens) {
if (err) {...}
request.post({
'url': 'https://....',
'qs': {
'uploadType': 'multipart'
},
'headers' : {
'Authorization': 'Bearer ' + tokens.access_token
},
'multipart': [{
'Content-Type': 'application/json; charset=UTF-8',
'body': JSON.stringify(metadata)
},{
'Content-Type': 'application/json',
'body': data
}]
}, done);
});
});
}
According to google here , if I want to enable custom headers, I need to add it as "x-goog-meta-mycustomheader"
When I change my above metadata object to this:
var metadata = {
name: "name"
contentLanguage: "en",
"x-goog-meta-something": "completely different",
acl: [...]
};
It has no effect.
How do I add custom headers when uploading an item to google storage?
EDIT :
Note that this is a multipart load that uses the body of the first part as the metadata of the second part (which is the actual part). Details here
In particular:
If you have metadata that you want to send along with the data being loaded, you can make one request to multipart / related. As with simple media-only queries, this is a good choice if the data you are sending is small enough to download completely if the connection fails.
Part of the metadata: must come first, and the Content-Type must match one of the accepted metadata formats.
Media part: must be the second, and the Content-Type must match one of the ways allowed for MIME types.
This is why I use metadata as the title section, I have also tried all other combinations like putting "x-goog-meta-something" in all other places
source to share
Take a look at the JSON request builder: https://developers.google.com/storage/docs/json_api/v1/objects/insert
You will notice that it metadata
is a separate key in the body. Therefore, you need something like:
var metadata = {
name: "name"
contentLanguage: "en",
metadata: {
"something": "completely different",
},
acl: [...]
};
source to share