diff --git a/example/lib/main.dart b/example/lib/main.dart index 5e274fb..7066ca4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,4 @@ -import 'package:example/src/multi_image_picker_example.dart'; +import 'package:example/src/image_picker_example.dart'; import 'package:flutter/material.dart'; void main() { @@ -14,8 +14,8 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - // home: ImagePickerExample(), - home: MultiImagePickerExample(), + home: ImagePickerExample(), + // home: MultiImagePickerExample(), ); } } diff --git a/example/lib/src/image_picker_example.dart b/example/lib/src/image_picker_example.dart index 1ffd7cf..ed45e22 100644 --- a/example/lib/src/image_picker_example.dart +++ b/example/lib/src/image_picker_example.dart @@ -69,6 +69,7 @@ class _ImagePickerExampleState extends State { final res = await cloudinary.uploadFile( CloudinaryFile.fromFile( _pickedFile.path, + folder: 'hello-folder', ), ); print(res); diff --git a/example/pubspec.lock b/example/pubspec.lock index fad7cec..83819bd 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -42,7 +42,7 @@ packages: path: ".." relative: true source: path - version: "0.8.1" + version: "0.8.1+1" collection: dependency: transitive description: @@ -92,7 +92,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.1" + version: "0.13.3" http_parser: dependency: transitive description: @@ -181,7 +181,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -216,7 +216,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/lib/src/cloudinary_file.dart b/lib/src/cloudinary_file.dart index 909c84a..4302f00 100644 --- a/lib/src/cloudinary_file.dart +++ b/lib/src/cloudinary_file.dart @@ -14,6 +14,11 @@ class CloudinaryFile { /// The file name/path final String? identifier; + /// An optional folder name where the uploaded asset will be stored. + /// The public ID will contain the full path of the uploaded asset, + /// including the folder name. + final String? folder; + /// External url final String? url; @@ -31,14 +36,15 @@ class CloudinaryFile { bool get fromExternalUrl => url != null; /// [CloudinaryFile] instance - const CloudinaryFile( - {this.byteData, - this.filePath, - this.identifier, - this.url, - required this.resourceType, - this.tags}) - : assert( + const CloudinaryFile({ + this.resourceType: CloudinaryResourceType.Auto, + this.byteData, + this.filePath, + this.identifier, + this.url, + this.tags, + this.folder, + }) : assert( (byteData == null && filePath != null) || (byteData != null && filePath == null) || url != null, @@ -57,37 +63,49 @@ class CloudinaryFile { ); /// Instantiate [CloudinaryFile] from [ByteData] - factory CloudinaryFile.fromByteData(ByteData byteData, - {String? identifier, - CloudinaryResourceType resourceType: CloudinaryResourceType.Auto, - List? tags}) => + factory CloudinaryFile.fromByteData( + ByteData byteData, { + String? identifier, + CloudinaryResourceType resourceType: CloudinaryResourceType.Auto, + List? tags, + String? folder, + }) => CloudinaryFile( byteData: byteData, identifier: identifier, resourceType: resourceType, tags: tags, + folder: folder, ); /// Instantiate [CloudinaryFile] from [File] path - factory CloudinaryFile.fromFile(String path, - {String? identifier, - CloudinaryResourceType resourceType: CloudinaryResourceType.Auto, - List? tags}) => + factory CloudinaryFile.fromFile( + String path, { + String? identifier, + CloudinaryResourceType resourceType: CloudinaryResourceType.Auto, + List? tags, + String? folder, + }) => CloudinaryFile( filePath: path, identifier: identifier ??= path.split('/').last, resourceType: resourceType, tags: tags, + folder: folder, ); /// Instantiate [CloudinaryFile] from an external url - factory CloudinaryFile.fromUrl(String url, - {CloudinaryResourceType resourceType: CloudinaryResourceType.Auto, - List? tags}) => + factory CloudinaryFile.fromUrl( + String url, { + CloudinaryResourceType resourceType: CloudinaryResourceType.Auto, + List? tags, + String? folder, + }) => CloudinaryFile( url: url, identifier: url, resourceType: resourceType, + folder: folder, ); /// Convert [CloudinaryFile] to [MultipartFile] diff --git a/lib/src/cloudinary_public.dart b/lib/src/cloudinary_public.dart index 870fb47..8c49694 100644 --- a/lib/src/cloudinary_public.dart +++ b/lib/src/cloudinary_public.dart @@ -95,6 +95,10 @@ class CloudinaryPublic { ); } + if (file.folder != null) { + data['folder'] = file.folder!; + } + if (file.tags != null && file.tags!.isNotEmpty) { data['tags'] = file.tags!.join(','); } diff --git a/pubspec.lock b/pubspec.lock index 4b72ad7..abe96c0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -66,7 +66,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.1" + version: "0.13.3" http_parser: dependency: transitive description: @@ -113,7 +113,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -148,7 +148,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d0f4930..84d9940 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - http: ^0.13.1 + http: ^0.13.3 dev_dependencies: flutter_test: