Google Storage API custom header on node.js -
i using googleapis.auth.jwt authenticate , request multipart upload upload json files google storage, working expected.
here 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 google here if want include custom headers need add in form of "x-goog-meta-mycustomheader"
when change above metadata object this:
var metadata = { name: "name" contentlanguage: "en", "x-goog-meta-something": "completely different", acl: [...] }; it doesn't have affect.
how add custom headers when upload object google storage?
edit:
please notice multipart upload uses first part body metadata of second part (which actual part) see details here
especially:
if have metadata want send along data upload, can make single multipart/related request. simple, media-only requests, choice if data sending small enough upload again in entirety if connection fails.
metadata part: must come first, , content-type must match 1 of accepted metadata formats.
media part: must come second, , content-type must match 1 method's accepted media mime types.
this why use metadata header section, tried other combinations putting "x-goog-meta-something" in other places
take @ json request builder here: https://developers.google.com/storage/docs/json_api/v1/objects/insert
you'll notice metadata separate key in body. you'll want like:
var metadata = { name: "name" contentlanguage: "en", metadata: { "something": "completely different", }, acl: [...] };
Comments
Post a Comment