Nodejs-storage: How to create a new folder?

Created on 29 Dec 2017  路  1Comment  路  Source: googleapis/nodejs-storage

My program:

  • creates a file into the laptop filesystem - example of path "Users/myname/folder/file-1"
  • uploads the file using the filename - example of filename "Users/myname/folder/file-1"

but when I access the Google Cloud bucket, all files are stored in the root folder of the bucket

I would expect that it stores the file into the folder "Users/myname/folder/"

storage question

Most helpful comment

Solved by specifying the destination option

return storage
    .bucket(bucketName)
    .upload(filename, {
      destination: 'folder/'+filename,
    })
    .then(() => {
      console.log(`${filename} uploaded to ${bucketName}.`);
    })
    .catch((err) => {
      console.error('ERROR:', err);
    });

>All comments

Solved by specifying the destination option

return storage
    .bucket(bucketName)
    .upload(filename, {
      destination: 'folder/'+filename,
    })
    .then(() => {
      console.log(`${filename} uploaded to ${bucketName}.`);
    })
    .catch((err) => {
      console.error('ERROR:', err);
    });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

abutreca picture abutreca  路  3Comments

lukesneeringer picture lukesneeringer  路  4Comments

hstemplewski picture hstemplewski  路  4Comments

major-mann picture major-mann  路  5Comments

dfrankes picture dfrankes  路  3Comments