Upload image file to bucket success.

This commit is contained in:
Naida Vatric
2020-02-26 14:56:00 +01:00
parent b13b4bc7c2
commit bbd9dab30d
4 changed files with 18 additions and 29 deletions

View File

@@ -59,13 +59,10 @@ setInterval(checkUpNotify, 1000 * 60 * 60 * 24);
//Google storage req
const PROJECT_ID = "marketalarm";
const KEY_FILENAME = "marketalarm-262e746e533c.json"; //relative path
const KEY_FILENAME = ""; //relative path
const BUCKET_NAME = "marketalarm-photos";
//Tried implicitly creating with env credentials and direktcly as here
const storage = new Storage({
projectId: PROJECT_ID,
keyFilename: KEY_FILENAME
});
const storage = new Storage();
const bucket = storage.bucket(BUCKET_NAME);
@@ -77,8 +74,7 @@ app.get("/generateSignedURL", (req, res) => {
//Tried to define Google ID and private key while debugging
version: "v2", //tried v4 also
action: "write",
"Content-Type": "image/*",
//contentType: "image/*", //tried without and with specific image/png ex.
contentType: "image/*", //tried without and with specific image/png ex.
expires: Date.now() + 86400000
};
const filename = req.query.filename;
@@ -90,10 +86,6 @@ app.get("/generateSignedURL", (req, res) => {
console.log(`The signed url is ${url}.`);
res.header("Access-Control-Allow-Origin", "http://localhost:5000");
res.header("Access-Control-Allow-Methods", "PUT,OPTIONS");
res.header("Access-Control-Allow-Headers", "Content-Type, Origin");
res.header("Access-Control-Max-Age", "86400000");
res.status(200).send(url);
}
generateSignedUrl().catch(console.error);