Skip to content

Commit 21183b4

Browse files
committed
updated to version 1.0.1
1 parent 69d0c10 commit 21183b4

File tree

9 files changed

+188
-58
lines changed

9 files changed

+188
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
22

33
## 1.0.0
4+
45
- Initial version.

README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
# cloudinary
22

3-
A dart package to integrate Cloudinary API in Dart and Flutter.
3+
A dart package for to integrate [Cloudinary](https://cloudinary.com/) API into your dart and flutter app. This package is a wrapper around the [Cloudinary API](https://cloudinary.com/documentation/image_upload_api_reference).
44

55
[![pub package](https://img.shields.io/pub/v/cloudinary.svg)][pub]
6-
![GitHub license](https://img.shields.io/badge/license-BSD-3.0-blue.svg?style=flat)
6+
[![Flutter](https://img.shields.io/badge/Flutter-3.3.0-blue.svg)](https://flutter.io/)
7+
[![Dart](https://img.shields.io/badge/Dart-2.18.0-blue.svg)](https://www.dartlang.org/)
8+
[![Gem Version](https://badge.fury.io/rb/cloudinary.svg)](http://badge.fury.io/rb/cloudinary)
9+
[![Code Climate](https://codeclimate.com/github/nixrajput/cloudinary-dart/badges/gpa.svg)](https://codeclimate.com/github/nixrajput/cloudinary-dart)
10+
[![Test Coverage](https://codeclimate.com/github/nixrajput/cloudinary-dart/badges/coverage.svg)](https://codeclimate.com/github/nixrajput/cloudinary-dart/coverage)
711

812
## Installation
9-
The first thing is to add **cloudinary** as a dependency of your project, for this you can use the command:
1013

11-
**For purely Dart projects**
14+
Add **cloudinary** as a dependency of your project, for this you can use the command:
15+
16+
**For Dart projects**
17+
1218
```shell
1319
dart pub add cloudinary
1420
```
21+
1522
**For Flutter projects**
23+
1624
```shell
1725
flutter pub add cloudinary
1826
```
19-
This command will add **cloudinary_sdk** to the **pubspec.yaml** of your project.
20-
Finally you just have to run:
2127

22-
`dart pub get` **or** `flutter pub get` depending on the project type and this will download the dependency to your pub-cache
28+
This command will add **cloudinary** to the **pubspec.yaml** of your project.
29+
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
2330

2431
## Usage
32+
2533
### Initialize a Cloudinary object
34+
2635
```dart
2736
/// This three params can be obtained directly from your Cloudinary account Dashboard.
2837
/// The .signedConfig(...) factory constructor is recommended only for server side apps, where [apiKey] and
@@ -33,7 +42,9 @@ final cloudinary = Cloudinary.signedConfig(
3342
cloudName: cloudName,
3443
);
3544
```
45+
3646
or
47+
3748
```dart
3849
/// The .unsignedConfig(...) factory constructor is recommended for client side apps, where [apiKey] and
3950
/// [apiSecret] must not be used, so .basic(...) constructor allows to do later unsigned requests.
@@ -43,7 +54,9 @@ final cloudinary = Cloudinary.unsignedConfig(
4354
```
4455

4556
### Do a signed file upload
57+
4658
Recommended only for server side apps.
59+
4760
```dart
4861
final response = await cloudinary.upload(
4962
file: file.path,
@@ -62,12 +75,15 @@ Recommended only for server side apps.
6275
}
6376
6477
```
78+
6579
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
6680
The `cloudinary.upload(...)` function is fully documented, you can check the description to know what other options you have.
6781

6882
### Do a unsigned file upload
83+
6984
Recommended for server client side apps.
7085
The way to do this request is almost the same as above, the only difference is the `uploadPreset` which is required for unsigned uploads.
86+
7187
```dart
7288
final response = await cloudinary.unsignedUpload(
7389
file: file.path,
@@ -87,10 +103,12 @@ The way to do this request is almost the same as above, the only difference is t
87103
}
88104
89105
```
106+
90107
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
91108
The `cloudinary.unsignedUpload(...)` function is fully documented, you can check the description to know what other options you have.
92109

93110
### Do a file delete *(this will use the cloudinary destroy method)*
111+
94112
```dart
95113
final response = await cloudinary.destroy('public_id',
96114
url: url,
@@ -101,10 +119,19 @@ The `cloudinary.unsignedUpload(...)` function is fully documented, you can check
101119
//Do something else
102120
}
103121
```
122+
104123
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...
105124
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
106125
The `cloudinary.destroy(...)` function is fully documented, you can check the description to know what other options you have.
107126

127+
## About Cloudinary
128+
129+
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.
130+
131+
## Get Help
132+
If you run into an issue or have a question, you can either:
133+
- Issues related to the SDK: [Open a Github issue](https://github.com/nixrajput/cloudinary-dart/issues).
134+
108135
## Connect With Me
109136

110137
[<img align="left" alt="nixrajput | Website" width="24px" src="https://raw.githubusercontent.com/nixrajput/nixlab-files/master/images/icons/globe-icon.svg" />][website]

lib/src/api_client/cloudinary_api.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ import 'dart:convert';
33
import 'package:crypto/crypto.dart';
44
import 'package:dio/dio.dart';
55

6-
/// Cloudinary API abstraction class
6+
/// Cloudinary API abstraction class for making requests to the Cloudinary API
7+
/// It uses the [Dio] to make the requests
78
abstract class CloudinaryApi {
9+
/// The [defaultUrl] is the base url for the cloudinary api
810
static const defaultUrl = 'https://api.cloudinary.com/v1_1/';
11+
12+
/// The [Dio] object used to make the upload requests
913
final Dio _dio;
14+
15+
/// The [Dio] object used to make the delete requests
1016
final Dio _deleteDio;
1117

18+
/// CloudinaryApi constructor used to initialize the [Dio] objects
19+
/// It takes the [apiKey], [apiSecret] and [cloudName] as parameters
20+
/// to build the [defaultUrl]
1221
CloudinaryApi({String? apiKey, String? apiSecret})
1322
: _dio = Dio(BaseOptions(baseUrl: '$defaultUrl/')),
1423
_deleteDio = Dio(
@@ -20,6 +29,7 @@ abstract class CloudinaryApi {
2029
),
2130
);
2231

32+
/// Post request to the cloudinary api
2333
Future<Response<T>> post<T>(
2434
String path, {
2535
data,
@@ -40,6 +50,7 @@ abstract class CloudinaryApi {
4050
);
4151
}
4252

53+
/// Delete request to the cloudinary api
4354
Future<Response<T>> delete<T>(
4455
String path, {
4556
data,

lib/src/api_client/cloudinary_api_client.dart

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@ import 'package:cloudinary/src/enums/cloudinary_resource_type.dart';
33
import 'package:cloudinary/src/models/cloudinary_response.dart';
44
import 'package:dio/dio.dart';
55

6+
/// Cloudinary Api Client class
7+
/// This class is used to make the requests to the cloudinary api
68
class CloudinaryApiClient extends CloudinaryApi {
79
static const _signedRequestAssertMessage = 'This endpoint requires an '
810
'authorized request, check the Cloudinary constructor you are using and '
911
'make sure you are using a valid `apiKey`, `apiSecret` and `cloudName`.';
1012

13+
/// The [apiKey] used to make the authorized requests
1114
final String apiKey;
15+
16+
/// The [apiSecret] used to make the authorized requests
1217
final String apiSecret;
18+
19+
/// The [cloudName] used to make the requests
1320
final String cloudName;
1421

22+
/// The [CloudinaryApiClient] constructor used to initialize the class
23+
/// [apiKey] is used to make the authorized requests
24+
/// [apiSecret] is used to make the authorized requests
25+
/// [cloudName] is used to make the requests
1526
CloudinaryApiClient({
1627
required this.apiKey,
1728
required this.apiSecret,
@@ -21,6 +32,7 @@ class CloudinaryApiClient extends CloudinaryApi {
2132
apiSecret: apiSecret,
2233
);
2334

35+
/// Returns if the [CloudinaryApiClient] is authorized or not
2436
bool get isBasic => apiKey.isEmpty || apiSecret.isEmpty || cloudName.isEmpty;
2537

2638
/// Uploads a file of [resourceType] with [fileName] to a [folder]
@@ -31,10 +43,12 @@ class CloudinaryApiClient extends CloudinaryApi {
3143
/// [fileBytes] byte array of the file to uploaded
3244
/// [resourceType] defaults to [CloudinaryResourceType.auto]
3345
/// [fileName] is not mandatory, if not specified then a random name will be used
34-
/// [optParams] a Map of optional parameters as defined in https://cloudinary.com/documentation/image_upload_api_reference
46+
/// [optParams] a Map of optional parameters as defined in
47+
/// https://cloudinary.com/documentation/image_upload_api_reference
3548
///
3649
/// Response:
37-
/// Check all the attributes in the CloudinaryResponse to get the information you need... including secureUrl, publicId, etc.
50+
/// Check all the attributes in the CloudinaryResponse to get the information
51+
/// you need... including secureUrl, publicId, etc.
3852
///
3953
/// Official documentation: https://cloudinary.com/documentation/upload_images
4054
@@ -64,13 +78,16 @@ class CloudinaryApiClient extends CloudinaryApi {
6478
}
6579
if (folder != null) params['folder'] = folder;
6680

67-
/// Setting the optParams... this would override the public_id and folder if specified by user.
81+
/// Setting the optParams... this would override the public_id and folder
82+
/// if specified by user.
6883
if (optParams != null) params.addAll(optParams);
6984
params['api_key'] = apiKey;
7085
params['file'] = fileBytes != null
71-
? MultipartFile.fromBytes(fileBytes,
86+
? MultipartFile.fromBytes(
87+
fileBytes,
7288
filename:
73-
fileName ?? DateTime.now().millisecondsSinceEpoch.toString())
89+
fileName ?? DateTime.now().millisecondsSinceEpoch.toString(),
90+
)
7491
: await MultipartFile.fromFile(file!, filename: fileName);
7592
params['timestamp'] = timeStamp;
7693
params['signature'] =
@@ -107,12 +124,15 @@ class CloudinaryApiClient extends CloudinaryApi {
107124
/// [fileBytes] byte array of the file to uploaded
108125
/// [resourceType] defaults to [CloudinaryResourceType.auto]
109126
/// [fileName] is not mandatory, if not specified then a random name will be used
110-
/// [optParams] a Map of optional parameters as defined in https://cloudinary.com/documentation/image_upload_api_reference
127+
/// [optParams] a Map of optional parameters as defined in
128+
/// https://cloudinary.com/documentation/image_upload_api_reference
111129
///
112130
/// Response:
113-
/// Check all the attributes in the CloudinaryResponse to get the information you need... including secureUrl, publicId, etc.
131+
/// Check all the attributes in the CloudinaryResponse to get the information
132+
/// you need... including secureUrl, publicId, etc.
114133
///
115-
/// Official documentation: https://cloudinary.com/documentation/upload_images#unsigned_upload
134+
/// Official documentation:
135+
/// https://cloudinary.com/documentation/upload_images#unsigned_upload
116136
Future<CloudinaryResponse> unsignedUpload({
117137
String? file,
118138
required String uploadPreset,
@@ -138,7 +158,8 @@ class CloudinaryApiClient extends CloudinaryApi {
138158
'public_id': publicId ?? fileName,
139159
if (folder != null) 'folder': folder,
140160

141-
/// Setting the optParams... this would override the public_id and folder if specified by user.
161+
/// Setting the optParams... this would override the public_id and folder
162+
/// if specified by user.
142163
if (optParams?.isNotEmpty ?? false) ...optParams!,
143164
};
144165

@@ -173,10 +194,14 @@ class CloudinaryApiClient extends CloudinaryApi {
173194
/// Deletes a file of [resourceType] with [publicId]
174195
/// from your specified [cloudName]
175196
///
176-
/// [publicId] The identifier of the uploaded asset. Note: The public ID value for images and videos should not include a file extension. Include the file extension for raw files only.
197+
/// [publicId] The identifier of the uploaded asset. Note: The public ID value
198+
/// for images and videos should not include a file extension. Include the
199+
/// file extension for raw files only.
177200
/// [resourceType] defaults to [CloudinaryResourceType.image]
178-
/// [invalidate] If true, invalidates CDN cached copies of the asset (and all its transformed versions). Default: false.
179-
/// [optParams] a Map of optional parameters as defined in https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
201+
/// [invalidate] If true, invalidates CDN cached copies of the asset (and all
202+
/// its transformed versions). Default: false.
203+
/// [optParams] a Map of optional parameters as defined in
204+
/// https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
180205
///
181206
/// Response:
182207
/// Check response.isResultOk to know if the file was successfully deleted.

lib/src/cloudinary_base.dart

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import 'package:cloudinary/src/enums/cloudinary_resource_type.dart';
33
import 'package:cloudinary/src/models/cloudinary_response.dart';
44
import 'package:dio/dio.dart';
55

6+
/// Cloudinary Base class
7+
/// This class is used to upload and delete resources from cloudinary
8+
/// It uses the [CloudinaryApiClient] to make the requests
9+
/// It uses the [CloudinaryResponse] to parse the response
10+
/// It uses the [CloudinaryResourceType] to define the resource type
11+
/// It uses the [Dio] to make the requests
612
class Cloudinary {
713
late final CloudinaryApiClient _client;
814

@@ -29,7 +35,10 @@ class Cloudinary {
2935
'None of `apiKey`, `apiSecret`, or `cloudName` '
3036
'must be empty.');
3137
return Cloudinary._(
32-
apiKey: apiKey, apiSecret: apiSecret, cloudName: cloudName);
38+
apiKey: apiKey,
39+
apiSecret: apiSecret,
40+
cloudName: cloudName,
41+
);
3342
}
3443

3544
/// Use this constructor when you don't need to make authorized requests
@@ -46,14 +55,8 @@ class Cloudinary {
4655

4756
/// Uploads a file of [resourceType] with [fileName] to a [folder]
4857
/// in your specified [cloudName]
49-
///
50-
/// [resource] A [CloudinaryUploadResource] object with all necessary data
51-
///
5258
/// Response:
53-
/// Check all the attributes in the CloudinaryResponse to get the information you need... including secureUrl, publicId, etc.
54-
/// See also:
55-
///
56-
/// * [CloudinaryUploadResource], to know which data to set
59+
/// [CloudinaryResponse], to know which data to get from the response
5760
Future<CloudinaryResponse> upload({
5861
String? file,
5962
List<int>? fileBytes,
@@ -81,14 +84,8 @@ class Cloudinary {
8184
/// specify an [apiKey] nor [apiSecret].
8285
///
8386
/// Make sure you set a [uploadPreset] in your resource.
84-
///
85-
/// [resource] A [CloudinaryUploadResource] object with all necessary data
86-
///
8787
/// Response:
88-
/// Check all the attributes in the CloudinaryResponse to get the information you need... including secureUrl, publicId, etc.
89-
/// See also:
90-
///
91-
/// * [CloudinaryUploadResource], to know which data to set
88+
/// [CloudinaryResponse], to know which data to get from the response
9289
Future<CloudinaryResponse> unsignedUpload({
9390
String? file,
9491
required String? uploadPreset,
@@ -117,17 +114,24 @@ class Cloudinary {
117114

118115
/// Deletes a file of [resourceType] with [publicId]
119116
/// from your specified [cloudName]
120-
/// By using the Destroy method of cloudinary api. Check here https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
117+
/// By using the Destroy method of cloudinary api. Check here
118+
/// https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
121119
///
122-
/// [publicId] the asset id in your [cloudName], if not provided then [url] would be used. Note: The public ID value for images and videos should not include a file extension. Include the file extension for raw files only.
123-
/// [url] the url to the asset in your [cloudName], the publicId will be taken from here
124-
/// [cloudinaryImage] a Cloudinary Image to be deleted, the publicId will be taken from here
120+
/// [publicId] the asset id in your [cloudName], if not provided then [url]
121+
/// would be used. Note: The public ID value for images and videos should not
122+
/// include a file extension. Include the file extension for raw files only.
123+
/// [url] the url to the asset in your [cloudName], the publicId will be taken
124+
/// from here
125+
/// [cloudinaryImage] a Cloudinary Image to be deleted, the publicId will
126+
/// be taken from here
125127
/// [resourceType] defaults to [CloudinaryResourceType.image]
126-
/// [invalidate] If true, invalidates CDN cached copies of the asset (and all its transformed versions). Default: false.
127-
/// [optParams] a Map of optional parameters as defined in https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
128+
/// [invalidate] If true, invalidates CDN cached copies of the asset (and all
129+
/// its transformed versions). Default: false.
130+
/// [optParams] a Map of optional parameters as defined in
131+
/// https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
128132
///
129133
/// Response:
130-
/// Check response.isResultOk to know if the file was successfully deleted.
134+
/// Check [CloudinaryResponse.isResultOk] to know if the file was successfully deleted.
131135
Future<CloudinaryResponse> destroy(
132136
String? publicId, {
133137
String? url,
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
/// Cloudinary resource type enum
1+
/// CloudinaryResponseType enum is used to specify the type of the resource
22
enum CloudinaryResourceType {
3+
/// The [image] type
34
image,
5+
6+
/// The [raw] type
47
raw,
8+
9+
/// The [video] type
510
video,
11+
12+
/// The [auto] type
613
auto,
714
}

0 commit comments

Comments
 (0)