Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4b76c61
add public_id field to upload params
jaedag Sep 21, 2022
bf7ea73
Merge pull request #22 from jaedag/master
djade007 Sep 21, 2022
bb1c280
Bump version
djade007 Sep 21, 2022
3eda390
- Added function to add file in chunks
rajan-nonstopio Oct 23, 2022
d0e95d8
- Added ti multipart chunk function
rajan-nonstopio Oct 23, 2022
90b7fc2
Fix Issues
rajan-nonstopio Oct 23, 2022
f1cbf3a
Update test cases
rajan-nonstopio Oct 24, 2022
05f61d3
remove keys from test cases
rajan-nonstopio Oct 27, 2022
e2a4e86
- Upload file in byte data fix errors
rajan-nonstopio Oct 27, 2022
97f0514
- Make identifier required and non null field
rajan-nonstopio Oct 28, 2022
81829b4
Fix chunk size
rajan-nonstopio Oct 29, 2022
829b371
Added current upload index
rajan-nonstopio Oct 29, 2022
fe378e3
Upload Readme and version
rajan-nonstopio Oct 29, 2022
4f4503d
Remove print
rajan-nonstopio Nov 16, 2022
ed1e8e0
Merge pull request #24 from rajan-nonstopio/master
djade007 Nov 16, 2022
ecb29b2
Add dart analysis
djade007 Nov 16, 2022
e88e574
Fix failing tests
djade007 Nov 16, 2022
49b7e5c
add github workflow
djade007 Nov 16, 2022
fe795ce
Setup env file in github workflow
djade007 Nov 16, 2022
5d6f907
fix file name
djade007 Nov 16, 2022
fa25c2a
Merge pull request #25 from djade007/chore/lint
djade007 Nov 16, 2022
a9adb64
fix upload on web
djade007 Nov 16, 2022
014c8d7
Upgrade dio dependency
djade007 May 1, 2023
66dba3d
chore: update dio version
djade007 Nov 28, 2023
d938845
chore: Update sdk constraint
djade007 Nov 28, 2023
1132b55
chore: fix deprecated method
djade007 Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test Cloudinary Library

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Install dependencies
run: flutter pub get
- name: Copy env file
run: cp example/lib/src/.init.example.dart example/lib/src/init.dart
- name: Analyze
run: flutter analyze
- name: Tests
run: flutter test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.23.1
- Update dio dependency and sdk constraints

## 0.20.0
- Upload large files in chunks support
- Switch from http package to Dio to support chunk upload

## 0.13.0
- add public_id option

## 0.12.0
- Update dependencies

Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ secretKey.

## Getting started

Add the dependency `cloudinary_public: ^0.11.0` to your project:
Add the dependency `cloudinary_public: ^0.23.1` to your project:

```dart
import 'package:cloudinary_public/cloudinary_public.dart';
Expand Down Expand Up @@ -109,4 +109,30 @@ final res = await cloudinary.uploadFile(
});
},
);
```

## Upload In Chunks
Use chunked upload when file size is more then 100 Megabytes.

By default, the chunk size is set to 20 Megabytes but can be set to as low as 5 Megabytes by using the chunk_size parameter.

Source: https://cloudinary.com/documentation/upload_images#chunked_asset_upload

```dart
final res = await cloudinary.uploadFileInChunks(
CloudinaryFile.fromFile(
_pickedFile.path,
folder: 'hello-folder',
context: {
'alt': 'Hello',
'caption': 'An example upload in chunks',
},
),
chunkSize: 10000000
onProgress: (count, total) {
setState(() {
_uploadingPercentage = (count / total) * 100;
});
},
);
```
32 changes: 32 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the modules of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
- avoid_print
- prefer_single_quotes
- always_declare_return_types
- require_trailing_commas
- avoid_dynamic_calls

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
18 changes: 10 additions & 8 deletions example/lib/example.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io';

import 'package:cloudinary_public/cloudinary_public.dart';
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';

main() async {
void main() async {
// set cache as true if you don't want to make an upload call with files of the same filename
// in such case if the filepath/identifier has already been uploaded before, you simply get the previously cached response.
var cloudinary =
Expand All @@ -13,14 +13,16 @@ main() async {
File file = File('');
try {
CloudinaryResponse response = await cloudinary.uploadFile(
CloudinaryFile.fromFile(file.path,
resourceType: CloudinaryResourceType.Image),
CloudinaryFile.fromFile(
file.path,
resourceType: CloudinaryResourceType.Image,
),
);

print(response.secureUrl);
debugPrint(response.secureUrl);
} on CloudinaryException catch (e) {
print(e.message);
print(e.request);
debugPrint(e.message);
debugPrint(e.request.toString());
}

// Using Byte Data. For example gotten from: https://pub.dev/packages/multi_image_picker
Expand All @@ -38,7 +40,7 @@ main() async {
.toList(),
);

print(uploadedImages[0].secureUrl);
debugPrint(uploadedImages[0].secureUrl);
}

class Asset {
Expand Down
20 changes: 11 additions & 9 deletions example/lib/src/image_picker_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class ImagePickerExample extends StatefulWidget {

class _ImagePickerExampleState extends State<ImagePickerExample> {
final picker = ImagePicker();
PickedFile _pickedFile;
XFile? _pickedFile;
bool _uploading = false;
double _uploadingPercentage = 0.0;

Future getImage() async {
final image = await picker.getImage(source: ImageSource.gallery);
final image = await picker.pickImage(source: ImageSource.gallery);

setState(() {
if (image != null) {
_pickedFile = image;
} else {
print('No image selected.');
debugPrint('No image selected.');
}
});
}
Expand Down Expand Up @@ -64,14 +64,16 @@ class _ImagePickerExampleState extends State<ImagePickerExample> {
}

Future<void> _upload() async {
if (_pickedFile == null) return;

setState(() {
_uploading = true;
});

try {
final res = await cloudinary.uploadFile(
CloudinaryFile.fromFile(
_pickedFile.path,
_pickedFile!.path,
folder: 'hello-folder',
context: {
'alt': 'Hello',
Expand All @@ -84,10 +86,10 @@ class _ImagePickerExampleState extends State<ImagePickerExample> {
});
},
);
print(res);
debugPrint(res.toString());
} on CloudinaryException catch (e) {
print(e.message);
print(e.request);
debugPrint(e.message);
debugPrint(e.request.toString());
}

setState(() {
Expand All @@ -98,8 +100,8 @@ class _ImagePickerExampleState extends State<ImagePickerExample> {

Widget _buildImage() {
if (kIsWeb) {
return Image.network(_pickedFile.path);
return Image.network(_pickedFile!.path);
}
return Image.file(File(_pickedFile.path));
return Image.file(File(_pickedFile!.path));
}
}
16 changes: 8 additions & 8 deletions example/lib/src/multi_image_picker_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class _MultiImagePickerExampleState extends State<MultiImagePickerExample> {
maxImages: 300,
enableCamera: true,
selectedAssets: images,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
cupertinoOptions: CupertinoOptions(takePhotoIcon: 'chat'),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "Example App",
allViewTitle: "All Photos",
actionBarColor: '#abcdef',
actionBarTitle: 'Example App',
allViewTitle: 'All Photos',
useDetailsView: false,
selectCircleStrokeColor: "#000000",
selectCircleStrokeColor: '#000000',
),
);
} on Exception catch (e) {
Expand Down Expand Up @@ -74,7 +74,7 @@ class _MultiImagePickerExampleState extends State<MultiImagePickerExample> {
children: <Widget>[
Center(child: Text('Error: $_error')),
ElevatedButton(
child: Text("Pick images"),
child: Text('Pick images'),
onPressed: loadAssets,
),
Expanded(
Expand Down Expand Up @@ -104,7 +104,7 @@ class _MultiImagePickerExampleState extends State<MultiImagePickerExample> {
.map(
(image) => CloudinaryFile.fromFutureByteData(
image.getByteData(),
identifier: image.identifier,
identifier: image.identifier ?? 'test',
),
)
.toList(),
Expand All @@ -114,6 +114,6 @@ class _MultiImagePickerExampleState extends State<MultiImagePickerExample> {
_uploading = false;
});

print(uploadedImages[0].secureUrl);
debugPrint(uploadedImages[0].secureUrl);
}
}
Loading