cloudinary / cloudinary_npm

Cloudinary NPM for node.js integration
629 stars 323 forks source link

Code is working in the development mode but it is not work in production mode , please help me #688

Closed SurajSanyol closed 2 months ago

SurajSanyol commented 2 months ago

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

const result = await cloudinary.uploader.upload(fileUri, options);

fs.promises.unlink(filePathUrl);
return result

} catch (error) { fs.promises.unlink(filePathUrl) // if there is an error, delete the temporary file

} }

export default cloudinaryUpload

SurajSanyol commented 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

wissam-khalili commented 2 months ago

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