Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload folders to GCS from node js using client library

To upload files to google-cloud-storage (gcs) from node there is documented process like

const Storage = require('@google-cloud/storage');
const storage = new Storage();
{
const bucket = storage.bucket("bt-name");
const res = await bucket.upload("./output_images/dir/file.png", {
            public: true
        });
}

But I want to upload entire dir to gcs in said bucket bt-name, when I try to do so it throws promise rejection error -- EISDIR: illegal operation on a directory, read

like image 257
Rohit Shisode Avatar asked Oct 12 '18 07:10

Rohit Shisode


1 Answers

It is not a built-in feature to upload a whole folder using the API or client library. If you would like to upload the whole folder, you would need your code to iterate through all the folder files in a loop and upload all of them one at a time, or you could use the recursive upload option with the command-line utility gsutil.

like image 79
Philipp Sh Avatar answered Nov 15 '22 00:11

Philipp Sh