From ba07b9311fecec471ad14ae5ec549f5823ec4c42 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 14 Feb 2020 15:34:33 +0100 Subject: [PATCH] WiP Signed url error. --- app/views/publishPhotos.ejs | 4 +++- index.js | 34 ++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/views/publishPhotos.ejs b/app/views/publishPhotos.ejs index 651862f..5acef77 100644 --- a/app/views/publishPhotos.ejs +++ b/app/views/publishPhotos.ejs @@ -57,12 +57,14 @@ var c = ""; function uploadFile(file) { $("#status").html('Starting Upload...') - url = c + url = c; + console.log("RADIL" + file); fetch(url, { method: 'PUT', body: file }) .then(response => response.text()) + .then (console.log()) .catch(error => $("#status").html(error) ) .then(response => $("#status").html('File uploaded successfully: ' + filename)); diff --git a/index.js b/index.js index f662853..7742726 100644 --- a/index.js +++ b/index.js @@ -75,26 +75,24 @@ async function generateSignedUrl() { //generateSignedUrl().catch(console.error); app.get("/generateSignedURL", (req, res) => { - console.log("Started server function!"); + async function generateSignedUrl() { + console.log("Started server function!"); - const options = { - version: "v2", - action: "write", - expires: Date.now() + 86400000 - }; - const filename = req.query.filename; + 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); + 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; - }); + const [url] = await bucket.file(filename).getSignedUrl(options); - console.log(`The signed url for ${filename} is ${url}.`); - res.send(url); + console.log(`The signed url for ${filename} is ${url}.`); + res.send(url); + } + + generateSignedUrl().catch(console.error); });