WiP File upload started.
This commit is contained in:
64
index.js
64
index.js
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user