Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix url with query string problem #71

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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