From 288766bfbe5b0376eb8a715728a354a42da0fd42 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Mon, 6 Feb 2023 13:36:45 +0330 Subject: [PATCH] Release v1.0.0 (#7) * Release v1.0.0 --- CHANGELOG.md | 7 ++++++ README.md | 46 ++++++++++++++++++++++++--------------- example/README.md | 29 ++++++++++++++++++++++++ lib/chunked_uploader.dart | 2 +- pubspec.yaml | 6 ++--- 5 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 example/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a5093d0..6009d6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.0.0] + +* **Breaking change**. Add new `upload` method to take file data stream and change + old `upload` method name to `uploadUsingFilePath`. This enables Web apps to upload files + without needing it's path. +* Add Ability to provide custom headers for each chunk upload request using `ChunkHeadersCallback` + ## [0.1.0] * Null safety diff --git a/README.md b/README.md index 2fb9839..0afe884 100644 --- a/README.md +++ b/README.md @@ -12,27 +12,37 @@ To use this plugin, add chunked_uploader as dependency in your pubspec.yaml file dependencies: flutter: sdk: flutter - chunked_uploader: ^0.1.0 - dio: ^4.0.0 + chunked_uploader: ^1.0.0 + file_picker: ^5.2.5 + dio: ^4.0.6 ``` ## Example ``` dart -import 'package:chunked_uploader/chunked_uploader.dart'; -import 'package:dio/dio.dart'; - -ChunkedUploader chunkedUploader = ChunkedUploader(Dio(BaseOptions( - baseUrl: 'https://example.com/api', - headers: {'Authorization': 'Bearer'}))); -try { - Response? response = await chunkedUploader.upload( - filePath: '/path/to/file', - maxChunkSize: 500000, - path: '/file', - onUploadProgress: (progress) => print(progress)); - print(response); -} on DioError catch (e) { - print(e); -} +final file = + (await FilePicker.platform.pickFiles(withReadStream: true))!.files.single; +final dio = Dio(BaseOptions( + baseUrl: 'https://example.com/api', + headers: {'Authorization': 'Bearer'}, +)); +final uploader = ChunkedUploader(dio); + +// using data stream +final response = await uploader.upload( + fileName: file.name, + fileSize: file.size, + fileDataStream: file.readStream!, + maxChunkSize: 500000, + path: '/file', + onUploadProgress: (progress) => print(progress), +); +// using path +final response = await uploader.uploadUsingFilePath( + fileName: file.name, + filePath: file.path!, + maxChunkSize: 500000, + path: '/file', + onUploadProgress: (progress) => print(progress), +); ``` diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..6150b95 --- /dev/null +++ b/example/README.md @@ -0,0 +1,29 @@ +# Example + +``` dart +final file = + (await FilePicker.platform.pickFiles(withReadStream: true))!.files.single; +final dio = Dio(BaseOptions( + baseUrl: 'https://example.com/api', + headers: {'Authorization': 'Bearer'}, +)); +final uploader = ChunkedUploader(dio); + +// using data stream +final response = await uploader.upload( + fileName: file.name, + fileSize: file.size, + fileDataStream: file.readStream!, + maxChunkSize: 500000, + path: '/file', + onUploadProgress: (progress) => print(progress), +); +// using path +final response = await uploader.uploadUsingFilePath( + fileName: file.name, + filePath: file.path!, + maxChunkSize: 500000, + path: '/file', + onUploadProgress: (progress) => print(progress), +); +``` diff --git a/lib/chunked_uploader.dart b/lib/chunked_uploader.dart index 29538cd..e5f6884 100644 --- a/lib/chunked_uploader.dart +++ b/lib/chunked_uploader.dart @@ -39,7 +39,7 @@ class ChunkedUploader { headersCallback: headersCallback, ).upload(); - Future uploadWithFilePath({ + Future uploadUsingFilePath({ required String filePath, required String fileName, required String path, diff --git a/pubspec.yaml b/pubspec.yaml index b801a98..df4f190 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: chunked_uploader -description: A plugin to upload files to server in chunks using Dio. -version: 0.1.0 +description: An easy-to-use package to upload files in chunks using Dio for mobile, desktop and web. +version: 1.0.0 homepage: https://github.com/Taskulu/chunked_uploader repository: https://github.com/Taskulu/chunked_uploader @@ -8,6 +8,6 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - dio: ^4.0.6 + dio: ">=4.0.0 <5.0.0" universal_io: ^2.0.4 async: ^2.9.0