WiP File upload started.

This commit is contained in:
Naida Vatric
2020-02-14 00:37:11 +01:00
parent 230ef60158
commit 34744613a7
3 changed files with 104 additions and 40 deletions

View File

@@ -56,27 +56,45 @@ setInterval(checkUpNotify, 1000 * 60 * 60 * 24);
//Google storage req
const storage = new Storage();
storage
.getBuckets()
.then(results => {
const buckets = results[0];
console.log("Buckets:");
buckets.forEach(bucket => {
console.log(bucket.name);
});
})
.catch(err => {
console.error("GOOGLE ERROR:", err);
});
const BUCKET_NAME = "kivi_original_photos";
const bucket = storage.bucket(BUCKET_NAME);
/*
bucket = gcs.bucket('aBucket')
bucket.file('aFile').getSignedUrl({
action: 'write',
expires: moment.utc().add(1, 'days').format(),
}, (error, signedUrl) => {
if (error == null) {
console.log(`Signed URL is ${signedUrl}`)
}
}) */
async function generateSignedUrl() {
const options = {
version: "v2",
action: "write",
expires: Date.now() + 86400000
};
const [url] = bucket.file("aFile").getSignedUrl(options);
console.log(`The signed url for aFile is ${url}.`);
return url;
}*/
//generateSignedUrl().catch(console.error);
app.get("/generateSignedURL", (req, res) => {
console.log("Started server function!");
const options = {
version: "v2",
action: "write",
expires: Date.now() + 86400000
};
const filename = req.query.filename;
console.log("Filename: ", filename);
console.log("Bucket name:", bucket.name);
const url = bucket.file(filename).getSignedUrl(options, function(err, url) {
if (err) {
console.error(err);
return;
}
return url;
});
console.log(`The signed url for ${filename} is ${url}.`);
res.send(url);
});