From 9d3b9a1a19c96bd324b55e7361a028c20dfc074f Mon Sep 17 00:00:00 2001 From: liubaishui Date: Fri, 11 Sep 2020 10:46:41 +0800 Subject: [PATCH 1/4] fixed for https://github.com/CarnegieTechnologies/gallery_saver/issues/66#issuecomment-674327340 --- lib/files.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/files.dart b/lib/files.dart index debc453..a77317c 100644 --- a/lib/files.dart +++ b/lib/files.dart @@ -25,8 +25,18 @@ bool isLocalFilePath(String path) { return !uri.scheme.contains(http); } -bool isVideo(String path) => - videoFormats.contains(extension(path).toLowerCase()); +bool isVideo(String path) { + bool output = false; + videoFormats.forEach((videoFormat) { + if (path.toLowerCase().contains(videoFormat)) output = true; + }); + return output; +} -bool isImage(String path) => - imageFormats.contains(extension(path).toLowerCase()); +bool isImage(String path) { + bool output = false; + imageFormats.forEach((imageFormat) { + if (path.toLowerCase().contains(imageFormat)) output = true; + }); + return output; +} From 5a4aa912ca6a6eed2c499bc8fa0a6147daf7ea63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B3=89?= Date: Fri, 11 Sep 2020 11:56:20 +0800 Subject: [PATCH 2/4] use uri parse to ignore url query string --- lib/gallery_saver.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/gallery_saver.dart b/lib/gallery_saver.dart index 77d0e5f..b9f0055 100644 --- a/lib/gallery_saver.dart +++ b/lib/gallery_saver.dart @@ -68,10 +68,12 @@ class GallerySaver { static Future _downloadFile(String url) async { print(url); http.Client _client = new http.Client(); - var req = await _client.get(Uri.parse(url)); + var fileUri = Uri.parse(url); + var req = await _client.get(fileUri); + var fileName = fileUri.pathSegments.last; var bytes = req.bodyBytes; String dir = (await getTemporaryDirectory()).path; - File file = new File('$dir/${basename(url)}'); + File file = new File('$dir/$fileName'); await file.writeAsBytes(bytes); print('File size:${await file.length()}'); print(file.path); From 304395e9ad6c782085c8a177cfaa33026e607cd1 Mon Sep 17 00:00:00 2001 From: Dmitri Lihhatsov <10514538+dimileeh@users.noreply.github.com> Date: Sat, 10 Oct 2020 18:21:48 +0100 Subject: [PATCH 3/4] Fix the parser for the downloaded file When a video is downloaded from Firebase Storage, it's filename has "/" encoded as "%2F", and as a result, we need to use Uri.parse two times, to get the actual file name instead of the full Cloud Storage path. --- lib/gallery_saver.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/gallery_saver.dart b/lib/gallery_saver.dart index b9f0055..0950adb 100644 --- a/lib/gallery_saver.dart +++ b/lib/gallery_saver.dart @@ -71,6 +71,9 @@ class GallerySaver { var fileUri = Uri.parse(url); var req = await _client.get(fileUri); var fileName = fileUri.pathSegments.last; + while (Uri.parse(fileName).pathSegments.length > 1) { + fileName = Uri.parse(fileName).pathSegments.last; + } var bytes = req.bodyBytes; String dir = (await getTemporaryDirectory()).path; File file = new File('$dir/$fileName'); From 6016585467ee5cd2dc58d260d5c3e4a06f9f772e Mon Sep 17 00:00:00 2001 From: liubaishui Date: Sun, 28 Mar 2021 20:55:18 +0800 Subject: [PATCH 4/4] Update pubspec.yaml --- pubspec.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index c5845ed..0c31514 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,14 +5,14 @@ author: Carnegie Technologies d.o.o homepage: https://github.com/CarnegieTechnologies/gallery_saver environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.10.0 <3.0.0" dependencies: flutter: sdk: flutter - path_provider: ^1.2.0 - http: ^0.12.0+2 - path: ^1.6.2 + path_provider: ^2.0.1 + http: ^0.13.1 + path: ^1.8.0 dev_dependencies: flutter_test: