You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
step 1 : take file from user to upload on server using multer diskStorage
step 2: After upload on the server then take the file from server and upload on the cloudinary;
step 3 : After successfully upload then remove the file from server
import { v2 as cloudinary } from 'cloudinary';
import fs from 'fs'
import path from 'path';
const cloudinaryUpload = async (filePathUrl, folder,file) => {
const options = {
use_filename: true,
unique_filename: false,
overwrite: true,
resource_type: 'auto',
folder: folder
};
// this is very important
const filePath = path.join(file.destination, file.filename);
const fileBuffer = await fs.promises.readFile(filePath);
const mime = file.mimetype;
const encoding = 'base64';
const base64Data = fileBuffer.toString('base64');
const fileUri = 'data:' + mime + ';' + encoding + ',' + base64Data;
try {
if (!filePath) return null;
// Upload the image
} catch (error) {
fs.promises.unlink(filePathUrl) // if there is an error, delete the temporary file
}
}
export default cloudinaryUpload
The text was updated successfully, but these errors were encountered: