Trying to upload to Google Cloud

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);
}

Did not check your code minutely but basically you cannot upload files to an external server using Corvid by just sending the filename.

Thank you. Is there any way to implement a upload to Google Cloud?

As a wise old Brewmaster once said to me :wink::tumbler_glass:

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.

@givemeawhisky I looked at that extensively. The issue here is to pass the filename from the frontend to the backend and then upload. This is quite different than taking information and posting it to a Google Sheet.

@mennyg19 Take a look at this: https://medium.com/@olamilekan001/image-upload-with-google-cloud-storage-and-node-js-a1cf9baa1876

@shantanukumar847
Excellent, thanks Shan :+1:

@mennyg19 In addition I would like to say that what you are trying to do is very advanced and if you do not have experience using JavaScript, Corvid & Google APIs I think you should start from something a little less complicated.

You can also checkout the Wix Arena which is a hub for Corvid (and other) experts for hire.