I have been facing an issue while attempting to upload a file to Google Cloud using a buffer and the save
function. The problem I am encountering is that even though the files are uploaded to Google Cloud, they are not in the correct format. When I try to download the files, they appear as .txt files of the buffer content.
I could really use some guidance on how to resolve this issue. Any assistance would be highly appreciated!
upload.ts
const upload = async (fileBuffer: any, filePath: string, fileName: string) => {
const file = bucket.file(path.join(filePath, fileName));
file.save(fileBuffer, (err: any) => {
if (err) {
console.log(err);
}
});
}
storage.ts
imageSender: async(req: Request, res: Response) => {
try {
const buffer = "";
await upload(buffer, "folder", "file");
res.status(200).send("The file was successfully uploaded.");
} catch (err) {
res.status(500).send(httpError(500, "Could not upload the file."));
}
},