Tuesday 15 May 2018

Upload Multiple Files in Directory to Google Cloud Bucket w/ Node

Hi all,Apologies if this is the wrong place to post thisI have a small project where I have a script that produces multiple reports (html,json files), once the reports are in a directory I'd like to upload those files at once to a google storage bucket. What's the best way to iterate through the contents of the directory and upload each file in one go? These files will be very small (~10mb dir total) so size isn't really a concern. Below is some sample code I was using to upload 1 individual file.Thanks in advance, I'm no java or node pro but I can usually frankenstein something together. I've seen lots of examples around the internet but they usually only pertain to one individual file.```java //gcp upload jsvar fs = require('fs');// Imports the Google Cloud client library const storage = require('@google-cloud/storage');var gcs = storage({ projectId: 'my-project', keyFilename: './my-key.json' });var bucket = gcs.bucket('fake_test_bucket');bucket.upload('./summary.json', function(err, file) { if (!err) { console.log("file is now in the bucket") } }); ```

Submitted May 15, 2018 at 08:18PM by krispey

No comments:

Post a Comment