Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 14 additions & 4 deletions lib/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 7 additions & 2 deletions lib/gallery_saver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ class GallerySaver {
static Future<File> _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;
while (Uri.parse(fileName).pathSegments.length > 1) {
fileName = Uri.parse(fileName).pathSegments.last;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simpler way might be the following:

var filename = basename(fileUri.path);

}
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);
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ author: Carnegie Technologies d.o.o <[email protected]>
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:
Expand Down