Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SurajSanyol opened this issue Sep 10, 2024 · 2 comments

Comments

@SurajSanyol
Copy link

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
Copy link
Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants