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);
}
As a wise old Brewmaster once said to me 😉🥃
Have a look at the Google Sheets NPM example which demonstrates how to use the Google APIs Node.js Client package included in the Wix Package Manager to access a Google Sheet.
You can see if you can adapt this example to access Google Cloud. See the Google docs and support for more information.
Did not check your code minutely but basically you cannot upload files to an external server using Corvid by just sending the filename.