This package allows you to upload media files directly to cloudinary, without exposing your apiKey or secretKey.
Add the dependency cloudinary_public: ^0.6.2
to your project and start using it:
import 'package:cloudinary_public/cloudinary_public.dart';
final cloudinary = CloudinaryPublic('CLOUD_NAME', 'UPLOAD_PRESET', cache: false);
Using Image Picker Plugin
var image = await ImagePicker.pickImage(source: ImageSource.camera);
CloudinaryResponse response = await cloudinary.uploadFile(
CloudinaryFile.fromFile(image.path, resourceType: CloudinaryResourceType.Image),
);
print(response.secureUrl);
Using Multi Image Picker Plugin
final images = await MultiImagePicker.pickImages(maxImages: 4);
List<CloudinaryResponse> uploadedImages = await cloudinary.multiUpload(
images
.map(
(image) => CloudinaryFile.fromFutureByteData(
image.getByteData(),
identifier: image.identifier,
),
)
.toList(),
);
print(uploadedImages[0].secureUrl);
// CloudinaryImage
final cloudinaryImage = CloudinaryImage('https://res.cloudinary.com/demo/image/upload/front_face.png');
// or using the image public id
final cloudinaryImage = cloudinary.getImage('front_face');
final String url = cloudinaryImage.transform().width(150).height(150).gravity('face').crop('thumb').generate();
// or using the shortcut
final String url = cloudinaryImage.thumbnail(width: 150, height: 150).generate();
// Chain example
final url = cloudinaryImage.transform()
.width(150)
.height(150)
.gravity('face')
.crop('thumb')
.chain()
.radius(20)
.chain()
.effect('sepia')
.chain()
.overlay(cloudinary.getImage('cloudinary_icon'))
.gravity('south_east')
.x(5)
.y(5)
.width(50)
.opacity(60)
.effect('brightness:200')
.chain()
.angle(10)
.generate();
// generates
// https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,h_150,w_150/r_20/e_sepia/e_brightness:200,g_south_east,l_cloudinary_icon,o_60,w_50,x_5,y_5/a_10/front_face.png