I'm trying to upload an image to a Google Cloud Storage bucket.
Here's my code:
import { Storage } from '@google-cloud/storage';
import { NextApiRequest } from 'next';
const bucketName = 'faqmaker';
export default async function handler(req: NextApiRequest, res) {
const storage = new Storage({
projectId: process.env.PROJECT_ID,
keyFilename: '@/lib/server/gcpKeyFile.json',
});
const bucket = storage.bucket(bucketName);
const fileName = req.query.file as string;
const options = {
destination: `logos/${fileName}`,
public: true,
};
bucket.upload(fileName, options, (error, file) => {
console.log('error: ', error);
console.log('file: ', file);
});
}
And here's the front:
const { logo } = values;
const logoName = encodeURIComponent(logo.name);
const { data } = await axios.get(
`${Routes.API.STORAGE.LOGO}?file=${logoName}`,
);
logo is a file of type File
I'm getting this error from the upload: ENOENT: no such file or directory