Open melitus opened 1 year ago
Get the error below when trying to view file uploaded on google cloud storage Seem express-fileupload does not work with google cloud storage when useTempFiles : true,
useTempFiles : true,
I tried setting the useTempFiles: true and passing the tempFIlePath to my google cloud storage functions it did not work. I got this when an image is saved - https://storage.googleapis.com/temp-hold-eu/Z0cuwDoD6-Screenshot%25202022-08-05%2520at%252017.21.28.png. This is my code shown below
const uploadToGCS = async ( file: Buffer, fileName: string, mimeType: string, ): Promise<string> => { const storage = new Storage({ keyFilename: config.googleBucket.serviceKeyPath, }); const bucket = storage.bucket(config.googleBucket.publicBucket); const gcsFileName = `${Date.now()}-${fileName}`; // Create a new blob in the bucket and upload the file data. const fileToUpload = bucket.file(gcsFileName); const fileStream = fileToUpload.createWriteStream({ metadata: { contentType: mimeType, }, resumable: false, }); return new Promise((resolve, reject) => { fileStream.on('finish', () => { const publicUrl = getPublicUrl(encodeURIComponent(fileToUpload.name)); fileToUpload .makePublic() .then(() => resolve(publicUrl)) .catch(reject); }); fileStream.on('error', (ex) => { Logger.log(ex, 'GCS'); return reject; }); fileStream.end(file); }); };
Hi,
Have you done any troubleshooting with your google environment?
This doesn't looks like related to the upload middleware at all.
Get the error below when trying to view file uploaded on google cloud storage Seem express-fileupload does not work with google cloud storage when
useTempFiles : true,
I tried setting the useTempFiles: true and passing the tempFIlePath to my google cloud storage functions it did not work. I got this when an image is saved - https://storage.googleapis.com/temp-hold-eu/Z0cuwDoD6-Screenshot%25202022-08-05%2520at%252017.21.28.png. This is my code shown below