CORS error still!

This commit is contained in:
Naida Vatric
2020-02-16 12:11:18 +01:00
parent 57df42dd05
commit 57329b0311
2 changed files with 7 additions and 26 deletions

View File

@@ -9,8 +9,8 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--file" id="status"></div> <div class="mdl-textfield mdl-js-textfield mdl-textfield--file" id="status"></div>
<script type="text/javascript"> <script type="text/javascript">
//Example - preuzeto
var c = ""; var c = "";
var filename = ""; var filename = "";
function uuidv4() { function uuidv4() {
@@ -58,7 +58,6 @@ var c = "";
function uploadFile(file) { function uploadFile(file) {
$("#status").html('Starting Upload...') $("#status").html('Starting Upload...')
url = c; url = c;
console.log("RADIL" + file);
fetch(url, { fetch(url, {
method: 'PUT', method: 'PUT',
headers: { headers: {
@@ -75,6 +74,6 @@ var c = "";
) )
.catch(error => $("#status").html(error) .catch(error => $("#status").html(error)
) )
.then(response => $("#status").html('File uploaded successfully: ' + filename + response.text())); .then(response => $("#status").html('File uploaded successfully: ' + filename + 'Response:' + response.text()));
} }
</script> </script>

View File

@@ -58,40 +58,23 @@ setInterval(checkUpNotify, 1000 * 60 * 60 * 24);
const PROJECT_ID = "marketalarm"; const PROJECT_ID = "marketalarm";
const KEY_FILENAME = "marketalarm-262e746e533c.json"; //relative path const KEY_FILENAME = "marketalarm-262e746e533c.json"; //relative path
const BUCKET_NAME = "marketalarm-photos"; const BUCKET_NAME = "marketalarm-photos";
//Tried implicitly creating with env credentials and direktcly as here
const storage = new Storage({ const storage = new Storage({
projectId: PROJECT_ID, projectId: PROJECT_ID,
keyFilename: KEY_FILENAME keyFilename: KEY_FILENAME
}); });
const bucket = storage.bucket(BUCKET_NAME); const bucket = storage.bucket(BUCKET_NAME);
/*
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) => { app.get("/generateSignedURL", (req, res) => {
async function generateSignedUrl() { async function generateSignedUrl() {
console.log("Started server function!"); console.log("Started server function!");
const options = { const options = {
// GoogleAccessID: //Tried to define Google ID and private key while debugging
// " kivi-original-photos-id@marketalarm.iam.gserviceaccount.com", version: "v2", //tried v4 also
// PrivateKey: "dd909e0aeef15920e7fc18229ce421246c143f90",
version: "v2",
action: "write", action: "write",
contentType: "image/*", contentType: "image/*", //tried without and with specific image/png ex.
expires: Date.now() + 86400000 expires: Date.now() + 86400000
}; };
const filename = req.query.filename; const filename = req.query.filename;
@@ -104,6 +87,5 @@ app.get("/generateSignedURL", (req, res) => {
console.log(`The signed url for ${filename} is ${url}.`); console.log(`The signed url for ${filename} is ${url}.`);
res.send(url); res.send(url);
} }
generateSignedUrl().catch(console.error); generateSignedUrl().catch(console.error);
}); });