Google-cloud-node: Problems writing to directory within bucket

Created on 17 May 2017  路  1Comment  路  Source: googleapis/google-cloud-node

I can't seem to upload a file to a folder within a bucket.

var bucket = gcs.bucket('my_bucket/test/');

bucket.upload('hello.txt', function(err, file) {
  if (!err) {
    console.log("success");
  }else{
    console.log(err);
  }
});

This throws ApiError: Not Found

Am I doing this right? It works when I don't try to put it inside the folder.

question storage

Most helpful comment

Good question! Technically, the Bucket name is the first part, "my_bucket". The file name can have a simulated directory structure by including the "path" in its name. So, basically:

var bucket = gcs.bucket('my_bucket')

bucket.upload('hello.txt', {
  destination: 'test/hello.txt'
}, function...

Or to reference the file directly:

var bucket = gcs.bucket('my_bucket')
var file = bucket.file('test/hello.txt')

>All comments

Good question! Technically, the Bucket name is the first part, "my_bucket". The file name can have a simulated directory structure by including the "path" in its name. So, basically:

var bucket = gcs.bucket('my_bucket')

bucket.upload('hello.txt', {
  destination: 'test/hello.txt'
}, function...

Or to reference the file directly:

var bucket = gcs.bucket('my_bucket')
var file = bucket.file('test/hello.txt')
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mik115 picture mik115  路  5Comments

dsimmons picture dsimmons  路  4Comments

vvzen picture vvzen  路  4Comments

sporkd picture sporkd  路  5Comments

VikramTiwari picture VikramTiwari  路  3Comments