Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Upload_images_to_Cloudinary_by_following_these_easy_steps:
- Create an account on Cloudinary.
- Obtain your cloud name, API key, and API secret.
- Then, write the simplest code.
- ================================
- import { v2 as cloudinary } from 'cloudinary';
- cloudinary.config({
- cloud_name: CLOUDINARY_CLOUD_NAME,
- api_key: CLOUDINARY_API_KEY,
- api_secret: CLOUDINARY_API_SECRET,
- });
- export const uploadImageWithCloudinary = async (data: string) => {
- //data is base64 data
- try {
- const result = await cloudinary.uploader.upload(data,
- { folder: 'folderName', format: '' }
- );
- return { id: result.public_id, url: result.secure_url };
- } catch (error) {
- return { id: '', url: '' };
- }
- };
Add Comment
Please, Sign In to add comment