Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YacheLee/6f4aaaab4bf3a25e3661385eae23ea3c to your computer and use it in GitHub Desktop.
Save YacheLee/6f4aaaab4bf3a25e3661385eae23ea3c to your computer and use it in GitHub Desktop.
var gcloud = require('google-cloud');
var storage = gcloud.storage;
var fs = require('fs');
module.exports = ()=> {
return new Promise((resolve, reject)=> {
var gcs = storage({
projectId: 'PROJECT_ID',
keyFilename: __dirname+'/keys.json'
});
var bucket = gcs.bucket('dentaltw');
findAllFiles(bucket)
.then((files)=> {
const promises = [];
files.forEach((file, i)=> {
promises.push(file.makePublic());
});
Promise.all(promises).then(()=>{
console.log("ok");
resolve();
});
})
.catch((err)=> {
reject(err);
});
});
function findAllFiles(bucket){
return new Promise((resolve, reject)=> {
bucket.getFiles((err, files)=> {
if(err){reject(err);}
resolve(files);
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment