0

I have gcloud set up in my application and I seem to be successfully authenticated. I can run the following without any problem:

GoogleCloud = require('gcloud')({ /* my credentials */ });
GoogleCloud.storage().createBucket('myBucket', function (err, res) {});

I can also do the following to retrieve my bucket and file without any problem:

var bucket = GoogleCloud.storage().bucket('myBucket');
var file = bucket.file('myFileName.ext');

And when I file.getMetadata(), I see the empty object convert to the expected information.

However, when I attempt to download the file, I get problems.

var pathToFileName = 'public/test.pdf';
file.download({ destination: pathToFileName }, function (err) { console.log(err); });
{ [Error: ENOENT, open '/public/test.pdf'] errno: 34, code: 'ENOENT', path: '/public/test.pdf' }

I have tried prepending the pathToFileName with /, ./, and ../ with no success. This is the same error that I have have gotten in the past with my configuration was not authorized or the file name was incorrect (although I was then unable to create buckets and get metadata). But is there still possibly an issue with acl or some other permission that I'm not aware of?

Zachary Newman
  • 20,014
  • 4
  • 39
  • 37
Micah Alcorn
  • 2,363
  • 2
  • 22
  • 45
  • What do you need to do with this PDF file ? I suspect downloading it to the `/public` folder of your app and serving it back to the client, which you can't achieve this way, and anyway you don't really want to serve static files within your Meteor app. If you need to process the file, save it to `/tmp/Random.id().pdf`, reupload it to the bucket and get a signed URL. The reason of your error is that the path does not resolve to anything on the filesystem (ENOENT), you can see what's the current working directory of the node app using `process.cwd()`. – saimeunt Aug 31 '15 at 01:05
  • @saimeunt my eventual goal is to pipe the readable stream from the bucket to the client. My reasoning is so that I can manage the permissions from my application and use only the admin connection to Google Cloud Storage. My first step was to save the file locally, serve it to the client, and then delete it from the fs. Am I going about this the wrong way? – Micah Alcorn Aug 31 '15 at 02:13
  • 3
    Seems like overkill, what I'd do in this case is set the bucket ACL to private, and use a Meteor client method to request a signed URL to access a specific file, this way you can handle the permission logic inside your app and let Google Cloud Storage handle the actual file serving, which they'll do better than your app. https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.20.0/storage/file?method=getSignedUrl – saimeunt Aug 31 '15 at 02:45
  • I don't think gcloud generally returns this kind of error, have you tested simply downloading the file to confirm that is indeed your issue? e.g. don't write it anywhere, just receive the buffer. `file.download(function(err, contents) { console.log(err || contents); });` – callmehiphop Aug 31 '15 at 16:31
  • @saimeunt is it possible to post ur answer so other people can benefit from it. – George Jul 05 '16 at 22:35

0 Answers0