Hi, I am trying to #upload to #Google #Cloud and not getting any response and file is not uploading.
Here is my frontend code:
import { uploadGoogleFile } from 'backend/google/uploadFile';
export function button5_click(event) {
uploadGoogleFile('bucket-name', $w('#uploadButton1').value[0].name)
}
My #backend code is as follows (/backend/google/uploadFile.jsw):
const { Storage } = require('@google-cloud/storage');
import { getKey } from 'backend/google/getKey';
export async function uploadGoogleFile(bucketName, filename) {
const token = await getKey();
const storage = await new Storage({ projectId: "bucket-name", credentials: token });
async function uploadFile() {
console.log("starting...")
filename = "file:///C:/AlphaR/" + filename
await storage.bucket(bucketName).upload(filename, {
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000',
},
});
console.log(`${filename} uploaded to ${bucketName}.`);
}
uploadFile();
}
And here is the code to get the key. I tried this for just getting a file list from the #GoogleCloud bucket and it works. So its obviously and issue with uploads specifically. I am posting for reference:
import wixData from 'wix-data';
let options = {
"suppressAuth": true
};
export async function getKey() {
const response = await wixData.get("googleConfig", "googleKey", options)
if(response.length === 0) return null;
return JSON.parse(response.value);
}