0 purchases
cloudinary
cloudinary #
A dart package for to integrate Cloudinary API into your dart and flutter
app. This package is a wrapper around
the Cloudinary API.
Installation #
Add cloudinary as a dependency in your pubspec.yaml file:
dependencies:
cloudinary: "latest_version"
copied to clipboard
Finally you just have to run: dart pub get or flutter pub get depending on the project type
and this will download the dependency to your pub-cache.
And import it:
import 'package:cloudinary/cloudinary.dart';
copied to clipboard
Usage #
Initialize a Cloudinary object #
/// This three params can be obtained directly from your Cloudinary account Dashboard.
/// The .signedConfig(...) factory constructor is recommended only for server side apps, where [apiKey] and
/// [apiSecret] are secure.
final cloudinary = Cloudinary.signedConfig(
apiKey: apiKey,
apiSecret: apiSecret,
cloudName: cloudName,
);
copied to clipboard
or
/// The .unsignedConfig(...) factory constructor is recommended for client side apps, where [apiKey] and
/// [apiSecret] must not be used, so .basic(...) constructor allows to do later unsigned requests.
final cloudinary = Cloudinary.unsignedConfig(
cloudName: cloudName,
);
copied to clipboard
Do a signed file upload #
Recommended only for server side apps.
final response = await
cloudinary.upload
(
file: file.path,
fileBytes: file.readAsBytesSync(),
resourceType: CloudinaryResourceType.image,
folder: cloudinaryCustomFolder,
fileName: 'some-name',
progressCallback: (count, total) {
print(
'Uploading image from file with progress: $count/$total');
}),
);
if(response.isSuccessful) {
print('Get your image from with ${response.secureUrl}');
}
copied to clipboard
You can upload a file from path or byte array representation, you can also pass an optParams map
to do a more elaborated upload according
to https://cloudinary.com/documentation/image_upload_api_reference
The cloudinary.upload(...) function is fully documented, you can check the description to know
what other options you have.
Do a unsigned file upload #
Recommended for server client side apps.
The way to do this request is almost the same as above, the only difference is the uploadPreset
which is required for unsigned uploads.
final response = await
cloudinary.unsignedUpload
(
file: file.path,
uploadPreset: somePreset,
fileBytes: file.readAsBytesSync(),
resourceType: CloudinaryResourceType.image,
folder: cloudinaryCustomFolder,
fileName: 'some-name',
progressCallback: (count, total) {
print(
'Uploading image from file with progress: $count/$total');
})
);
if(response.isSuccessful) {
print('Get your image from with ${response.secureUrl}');
}
copied to clipboard
You can upload a file from path or byte array representation, you can also pass an optParams map
to do a more elaborated upload according
to https://cloudinary.com/documentation/image_upload_api_reference
The cloudinary.unsignedUpload(...) function is fully documented, you can check the description to
know what other options you have.
Do a file delete (this will use the cloudinary destroy method) #
final response = await
cloudinary.destroy
('public_id
'
,url: url,
resourceType: CloudinaryResourceType.image,
invalidate: false,
);
if(response.isSuccessful ?? false){
//Do something else
}
copied to clipboard
To delete a cloudinary file it´s necessary a public_id, as you can see in the sample code
the deleteResource(...) function can delete a file by it's url...
You can also pass an optParams map to do a more elaborated delete (destroy) according
to https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
The cloudinary.destroy(...) function is fully documented, you can check the description to know
what other options you have.
About Cloudinary #
Cloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers
to efficiently manage, transform, optimize, and deliver images and videos through multiple CDNs.
Ultimately, viewers enjoy responsive and personalized visual-media experiences—irrespective of the
viewing device.
Get Help #
If you run into an issue or have a question, you can either:
Issues related to the
SDK: Open a Github issue.
Connect With Me #
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.