Repository navigation
Closed
Labels
api: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.coretype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
v0.48.0 of google-cloud package is resulting in an error when attempting to upload a file.
The following code is enough to reproduce the issue.
import createGcloud from 'google-cloud';
const credentials = JSON.parse(new Buffer(process.env.GOOGLE_CLOUD_CREDENTIALS, 'base64').toString());
const gcloud = createGcloud({
credentials,
projectId: argv.googleProjectId
});
const gcs = gcloud.storage();
const bucket = gcs.bucket(argv.googleStorageBucketName);
const posterFilePath = 'replace with a file path';
await bucket.upload(posterFilePath, {
destination: 'posters/test.jpg',
gzip: true,
metadata: {
contentLanguage: 'en',
contentType: 'image/jpeg'
},
predefinedAcl: 'publicRead',
resumable: false,
validation: 'md5'
});The error itself is misleading (see #2069):
Error: Sorry, we cannot connect to Cloud Services without a project ID. You may specify one with an environment variable named "GCLOUD_PROJECT". See https://googlecloudplatform.github.io/google-cloud-node/#/docs/guides/authentication for a detailed guide on creating an authenticated connection.
at Object.<anonymous> (/Users/gajus/Documents/dev/applaudience/movie-editor/node_modules/google-cloud/node_modules/@google-cloud/common/src/util.js:55:29)
at Module._compile (module.js:571:32)
at Module._extensions..js (module.js:580:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/gajus/Documents/dev/applaudience/movie-editor/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/gajus/Documents/dev/applaudience/movie-editor/node_modules/google-cloud/node_modules/@google-cloud/common/src/service-object.js:32:12)
The real error originates here:
if (is.object(value) && is.fn(value.hasOwnProperty)) {
for (var opt in value) {
+ if (value.hasOwnProperty(opt)) {
value[opt] = replaceProjectIdToken(value[opt], projectId);
}
}
}The value Object does not have hasOwnProperty method.
The reqOpts object looks like this:
{ method: 'POST',
qs:
{ uploadType: 'multipart',
name: 'posters/poster-1000216-2017-beauty-and-the-beast.jpg',
predefinedAcl: 'publicRead' },
uri: 'https://www.googleapis.com/upload/storage/v1/b/applaudience/o',
multipart:
[ { 'Content-Type': 'application/json',
body: '{"contentLanguage":"en","contentType":"image/jpeg","metadata":{"applaudience-movie-id":1000216,"movie-release-year":"2017","movie-title":"Beauty and the Beast"},"contentEncoding":"gzip"}' },
{ 'Content-Type': 'image/jpeg', body: [Object] } ],
headers:
{ 'User-Agent': 'gcloud-node-storage/0.7.0',
Authorization: 'Bearer REDACTED' } }
value { end:
[ { [Function: bound onceWrapper] listener: [Function: onend] },
[Function: onend] ],
prefinish: { [Function: bound onceWrapper] listener: [Function] },
finish: [Function: onfinish],
error: { [Function: f] called: false },
close: [Function: onclose],
drain: [Function: ondrain] }
Not very useful, but confirms that the former code sample is creating the error.
For whatever reason (I didn't dig that deep), the object contained in the value property does not have hasOwnProperty method. In case relevant, Node.js v7.7.1.
Metadata
Metadata
Assignees
Labels
api: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.coretype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Activity
stephenplusplus commentedon Mar 9, 2017
This is interesting, and the same issue as #2050. We (tried to) fix that by adding
is.fn(value.hasOwnProperty)before attempting to callvalue.hasOwnProperty. The fix is in master, and released under@google-cloud/common@0.12.2, but didn't make it intogoogle-cloud@0.48.0. Can you try installing@google-cloud/storageand see if it was a satisfactory fix?gajus commentedon Mar 9, 2017
Just installing
@google-cloud/commonwill do no good.Something like this should work, though:
I can confirm that it fixes the problem.
Is there a workaround in the mean time that doesn't require deleting files?
stephenplusplus commentedon Mar 9, 2017
'google-cloud' is just a bundled package that includes all of the service APIs. So you can install just '@google-cloud/storage' and use it directly until the 'google-cloud' package is updated. Sorry you ran into this. I will try to put out a new release today.
abdulj commentedon May 1, 2017
I am running in to this issue since yesterday. The code is in cloud functions trying to access cloud storage using "@google-cloud/storage": "1.1.0" .
const Storage = require('@google-cloud/storage')();
Error: Sorry, we cannot connect to Cloud Services without a project ID. You may specify one with an environment variable named "GCLOUD_PROJECT". See https://googlecloudplatform.github.io/google-cloud-node/#/docs/guides/authentication for a detailed guide on creating an authenticated connection.
at Object. (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:55:29)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/service-object.js:32:12)
at Module._compile (module.js:570:32)"
The same cloud function also connects to datastore, which works without hitting this issue.
stephenplusplus commentedon May 1, 2017
@abdulj are you running a specific method in the Storage API when you see the error?
abdulj commentedon May 1, 2017
@stephenplusplus I tried the below written two ways , both leading to this error.
stephenplusplus commentedon May 1, 2017
@abdulj I've been trying and failing to reproduce. Could you try this isolated example and see that it still occurs? https://gist.github.com/stephenplusplus/adf3b2bf3a6df17d3178def4a31aba6c
abdulj commentedon May 1, 2017
@stephenplusplus thanks for the quick responses :) and sorry that I did not debug enough before commenting here.
Looks like I was passing an object for filename instead of a string, this was entity key from datastore. I wanted the entity key (numeric ID) to be used as filename, and passed the key object as filename. Error was misleading though. Thanks again.
stephenplusplus commentedon May 1, 2017
I'm glad it worked out! We have an issue to address the confusing error here: #2069 -- sorry for that :(
fix: correct STORAGE_EMULATOR_HOST handling (#2069, #1314) (#2070)
Revert "fix: correct STORAGE_EMULATOR_HOST handling (#2069, #1314) (#…
feat: add support for change streams transaction exclusion option for…
chore(main): release 7.10.0 (#2076)
feat: add support for blind writes (#2065)
fix: correct STORAGE_EMULATOR_HOST handling (googleapis#2069, googlea…
Revert "fix: correct STORAGE_EMULATOR_HOST handling (googleapis#2069, g…