Skip to content

Commit a5ffc95

Browse files
Fix #67: can not download file having empty character in name
Signed-off-by: huynguyennovem <huynguyennovem@gmail.com>
1 parent 776a929 commit a5ffc95

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/service/download_service.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class DownloadService {
4444
Function(InternalError)? onError,
4545
}) async {
4646
String? externalStorageDirPath;
47+
// fix https://github.com/huynguyennovem/netshare/issues/67:
48+
// file name has space > need to encode the uri
49+
String downloadFileUrl = fileUrl;
4750
if (Platform.isAndroid) {
4851
try {
4952
externalStorageDirPath = await AndroidPathProvider.downloadsPath;
@@ -54,26 +57,27 @@ class DownloadService {
5457
}
5558
} else if (Platform.isIOS) {
5659
externalStorageDirPath = (await getApplicationDocumentsDirectory()).absolute.path;
60+
downloadFileUrl = Uri.encodeFull(fileUrl);
5761
}
5862
if (null != externalStorageDirPath) {
5963
final savedDir = Directory(externalStorageDirPath);
6064
if (!savedDir.existsSync()) {
6165
await savedDir.create();
6266
}
6367
final taskId = await FlutterDownloader.enqueue(
64-
url: fileUrl,
68+
url: downloadFileUrl,
6569
savedDir: savedDir.path,
6670
saveInPublicStorage: true,
6771
);
6872
debugPrint('Download taskId: $taskId');
6973

7074
// add to stream
71-
final fileName = path.basename(fileUrl);
75+
final fileName = path.basename(downloadFileUrl);
7276
updateDownloadState(
7377
DownloadEntity(
7478
taskId ?? fileName,
7579
fileName,
76-
fileUrl,
80+
downloadFileUrl,
7781
savedDir.path,
7882
DownloadManner.flutterDownloader,
7983
DownloadState.downloading,

0 commit comments

Comments
 (0)