CORS error still!
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
<div class="mdl-textfield mdl-js-textfield mdl-textfield--file" id="status"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var c = "";
|
||||
//Example - preuzeto
|
||||
var c = "";
|
||||
var filename = "";
|
||||
|
||||
function uuidv4() {
|
||||
@@ -58,7 +58,6 @@ var c = "";
|
||||
function uploadFile(file) {
|
||||
$("#status").html('Starting Upload...')
|
||||
url = c;
|
||||
console.log("RADIL" + file);
|
||||
fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
@@ -75,6 +74,6 @@ var c = "";
|
||||
)
|
||||
.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>
|
||||
26
index.js
26
index.js
@@ -58,40 +58,23 @@ setInterval(checkUpNotify, 1000 * 60 * 60 * 24);
|
||||
const PROJECT_ID = "marketalarm";
|
||||
const KEY_FILENAME = "marketalarm-262e746e533c.json"; //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 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) => {
|
||||
async function generateSignedUrl() {
|
||||
console.log("Started server function!");
|
||||
|
||||
const options = {
|
||||
// GoogleAccessID:
|
||||
// " kivi-original-photos-id@marketalarm.iam.gserviceaccount.com",
|
||||
// PrivateKey: "dd909e0aeef15920e7fc18229ce421246c143f90",
|
||||
version: "v2",
|
||||
//Tried to define Google ID and private key while debugging
|
||||
version: "v2", //tried v4 also
|
||||
action: "write",
|
||||
contentType: "image/*",
|
||||
contentType: "image/*", //tried without and with specific image/png ex.
|
||||
expires: Date.now() + 86400000
|
||||
};
|
||||
const filename = req.query.filename;
|
||||
@@ -104,6 +87,5 @@ app.get("/generateSignedURL", (req, res) => {
|
||||
console.log(`The signed url for ${filename} is ${url}.`);
|
||||
res.send(url);
|
||||
}
|
||||
|
||||
generateSignedUrl().catch(console.error);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user