cloudinaryUpload method
void
cloudinaryUpload({})
Uploads one or more image files to Cloudinary using the specified upload preset and cloud name.
paths
is a list of file paths to upload.
uploadPreset
is the upload preset to use for the upload.
cloudName
is the name of the Cloudinary account to upload the files to.
onProgress
is an optional callback function that is called with the current progress of the upload, as a percentage.
onException
is an optional callback function that is called if an exception occurs during the upload.
The function is passed a CloudinaryException object.
Example usage:
RhUtils.instance.cloudinaryUpload(
paths: ['/path/to/image1.jpg', '/path/to/image2.png'],
uploadPreset: 'upload_preset',
cloudName: 'cloud_name',
onProgress: (sent, total) => print('$sent of $total bytes uploaded'),
onException: (e) => print('Upload failed: ${e.message}'),
);
Implementation
void cloudinaryUpload({
required List<String> paths,
required String uploadPreset,
required String cloudName,
void Function(int, int)? onProgress,
Function(CloudinaryException)? onException,
}) async {
final cloudinary = CloudinaryPublic(cloudName, uploadPreset);
if (paths.isNotEmpty) {
try {
for (var path in paths) {
await cloudinary.uploadFile(
CloudinaryFile.fromFile(path,
resourceType: CloudinaryResourceType.Image),
onProgress: onProgress);
}
} on CloudinaryException catch (e) {
if (onException != null) {
onException(e);
}
}
}
}