I have done upload using Multer in NodeJS if storage is memoryStorage, since file is save in buffer first, and than from buffer I can upload to Google Drive,
But if using memoryStorage I can not rename image file,
I using multer.diskStorage but when I post, file is succeed upload but not the picture, file size become small like 10B.
this is my code in helper with function uploadImage
const util = require('util')
const gc = require('../config/')
const bucket = gc.bucket('jsimage')//bucket name
const { format } = util
const uploadImage = (file) => new Promise((resolve, reject) => {
console.log(file);
//const { originalname, buffer } = file
const { filename, destination } = file
//const blob = bucket.file(originalname.replace(/ /g, "_"))
const blob = bucket.file(filename)
const blobStream = blob.createWriteStream({
resumable: false
})
blobStream.on('finish', () => {
const publicUrl = format(
`https://storage.googleapis.com/${bucket.name}/${blob.name}`
)
resolve(publicUrl)
})
.on('error', () => {
reject(`Unable to upload image, something went wrong`)
})
//.end(buffer)
.end(destination)
})
module.exports = uploadImage
with code above I succeed to upload in Google Drive but not the picture, since size is always 10B.