Closed SurajSanyol closed 2 months ago
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
these are the steps i am doing
Hi @SurajSanyol ,
I see that you have raised the same issue in our community forum: https://community.cloudinary.com/discussion/862/image-upload-on-cloudinary-in-the-development-mode-its-working-good-but-it-is-failed-in-production
I will close this request and I will continue the discussion in the community forum.
Thanks, Wissam
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