-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (36 loc) · 1.05 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var admin = require("firebase-admin");
const uuid = require('uuid-v4');
const path = require('path');
const fs = require('fs');
var serviceAccount = require("./<YOUR-FIREBASE-SERVICES-ACCOUNT-JSON-FILE.json>");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "<YOUR-FIREBASE-BUCKET-NAME>.appspot.com"
});
var bucket = admin.storage().bucket();
let i = 0;
const directoryPath = path.join(__dirname, 'pp');
fs.readdir(directoryPath, function (err, files) {
files.forEach(function (file) {
//console.log(file);
setTimeout(function(){
uploadFile("./pp/" + file);
}, i*3000); //3000->3 second
i++;
});
});
async function uploadFile(filename) {
const metadata = {
metadata: {
firebaseStorageDownloadTokens: uuid()
},
contentType: 'image/png',
cacheControl: 'public, max-age=31536000',
};
await bucket.upload(filename, {
gzip: true,
metadata: metadata,
});
console.log(`${filename} upload ok -> ` + new Date());
}
uploadFile().catch(console.error);