shopnilSS

Upload Image Free cost

Nov 13th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Upload_images_to_Cloudinary_by_following_these_easy_steps:
  2. Create an account on Cloudinary.
  3. Obtain your cloud name, API key, and API secret.
  4. Then, write the simplest code.
  5. ================================
  6. import { v2 as cloudinary } from 'cloudinary';
  7.  
  8. cloudinary.config({
  9. cloud_name: CLOUDINARY_CLOUD_NAME,
  10. api_key: CLOUDINARY_API_KEY,
  11. api_secret: CLOUDINARY_API_SECRET,
  12. });
  13.  
  14. export const uploadImageWithCloudinary = async (data: string) => {
  15. //data is base64 data
  16. try {
  17. const result = await cloudinary.uploader.upload(data,
  18. { folder: 'folderName', format: '' }
  19. );
  20. return { id: result.public_id, url: result.secure_url };
  21. } catch (error) {
  22. return { id: '', url: '' };
  23. }
  24. };
Add Comment
Please, Sign In to add comment