Comments (11)
Thanks, I followed this solution and now opening files works well: #85
from background_downloader.
final task = DownloadTask(
url: downloadStartRequest.url.toString(),
filename: downloadStartRequest
.url.queryParameters['fullFileName'] ??
'้ไปถ'); // define your task
pd ??= ProgressDialog(context: context);
pd!.show(
max: 100,
msg: localizations.downloadStatusRunning,
progressType: ProgressType.valuable,
progressBgColor: Colors.transparent,
hideValue: true,
closeWithDelay: 1000,
cancel: Cancel(
cancelClicked: () {
FileDownloader().cancelTaskWithId(task.taskId);
},
),
completed: Completed(
completedMsg: localizations.downloadStatusComplete),
// onStatusChanged:
);
TaskStatusUpdate result = await FileDownloader().download(
task,
);
if (result.status == TaskStatus.complete) {
pd!.update(
value: 100,
);
FileDownloader().openFile(task: task);
}
I alter the code to this. Still not work on android. It stuck in FileDownloader.dowload() without response.
The console logs "Enqueuing task with id xxxx"
from background_downloader.
Hi, thanks for trying the package. A few thoughts:
- You need to do something with the result of the call to
download
, for example to capture failures/errors - you shouldn't just ignore the return value - You need to make sure your url and urlQueryParameters are url encoded - it's not clear from the example that you do that and it will fail if you don't
from background_downloader.
bool result = await FileDownloader().enqueue(task);
if (result) {
pd!.update(
value: 100,
);
FileDownloader().openFile(task: task);
}
I just modify "download" to "enqueue" and successfully downloaded. But another error show:
Failed to open file /data/user/0/com.example.prime_layer_flutter/app_flutter/image3303709270623290067.jpg: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.prime_layer_flutter/app_flutter/image3303709270623290067.jpg
Did I miss any configurations?
from background_downloader.
For some reason (that I don't understand) on Android you can't open a file that is downloaded in the documents directory (the default for a Task). Download to a different directory (e.g. temporary) and it should work.
from background_downloader.
Looking at your code again, it seems like you try to open them file right after the call to enqueue. Enqueue does just that: puts the request in the queue. It doesn't compete the request. You need to listen to updates or register a handler.
Please read the documentation.
from background_downloader.
@override
void initState() {
super.initState();
FileDownloader().registerCallbacks(
taskStatusCallback: myDownloadStatusCallback,
);
}
void myDownloadStatusCallback(TaskStatusUpdate update) {
if (update.status == TaskStatus.complete) {
pd!.update(
value: 100,
);
FileDownloader().openFile(task: update.task);
}
}
I register a task status callback handler. But only the first state(enqueued) update was processed. The next state update did not occur.
from background_downloader.
I run the example. Same problem.
![image](https://private-user-images.githubusercontent.com/16433331/239844169-e5b45b09-b6a0-4918-b4eb-778bca3b2eae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0ODcwMzIsIm5iZiI6MTcyMTQ4NjczMiwicGF0aCI6Ii8xNjQzMzMzMS8yMzk4NDQxNjktZTViNDViMDktYjZhMC00OTE4LWI0ZWItNzc4YmNhM2IyZWFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIwVDE0NDUzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU1ZWNmNzJhN2RjMTFkNzg4MWEzMjc3NmYwZWUyMzVmYWQxODBkYTM0NDM5ZGU5NjdlYjA2OWI4Y2RiNzQwMjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.exMuHEmocuNUDB8zHY8FjMtn7RWFPEwtUwi2soekPGs)
from background_downloader.
If the example doesn't move past enqueued then that means the task does not complete, not even with an error (which would show in the example app).
Have you modified the example app to load a different file, or does the example app download the original file from the repo? If the original, there has to be an issue with how your device reaches the network (that app has always worked, so if it doesn't complete it means there is an issue with the network). If you've modified the example to load 'your' file then I think there is an issue with how you have defined your task, eg urlencoding etc.
Perhaps if you can provide:
- The version of the downloader you are using
- The version of Android
- Logs from the device (including those labeled TaskWorker and BackgroundDownloaderPlugin, as those are on the Kotlin side)
from background_downloader.
I also get the same error when I tap on a notification to open the file, or when I call .openFile(task: result.task)
:
java.lang.IllegalArgumentException: Failed to find configured root that contains ...
See my logs, the file does get downloaded:
I/BackgroundDownloader(25786): Enqueuing task with id 1152481977
I/flutter (25786): PXL_20230207_101333993.jpg status: TaskStatus.enqueued
I/TaskWorker(25786): Starting task with taskId 1152481977
I/flutter (25786): PXL_20230207_101333993.jpg status: TaskStatus.running
I/flutter (25786): PXL_20230207_101333993.jpg progress: 0.0%
I/TaskWorker(25786): Successfully downloaded taskId 1152481977 to /data/user/0/com.myapp.staging/app_flutter/PXL_20230207_101333993.jpg
I/flutter (25786): PXL_20230207_101333993.jpg progress: 100.0%
I/flutter (25786): PXL_20230207_101333993.jpg status: TaskStatus.complete
I/flutter (25786): Success!
I/WM-WorkerWrapper(25786): Worker result SUCCESS for Work [ id=bcdad762-6b32-4894-a235-9b0371f59dbd, tags={ com.bbflight.background_downloader.TaskWorker, BackgroundDownloader, taskId=1152481977, group=await } ]
Flutter 3.10.6
background_downloader: 7.9.4
Tested on both Android 11 & 13
from background_downloader.
Hi, per comment above, I think you're running into this:
For some reason (that I don't understand) on Android you can't open a file that is downloaded in the documents directory (the default for a Task). Download to a different directory (e.g. temporary) and it should work.
from background_downloader.
Related Issues (20)
- Error information for failed downloads HOT 2
- Pleas help me ,Compilation failed, unable to get kotlin-serialization-compiler-plugin-embeddable-1.7.10.pom
- Execution failed for task ':background_downloader:compileDebugKotlin' HOT 1
- How i can resolve this issue? HOT 2
- Downloader works on Android but not on IOs (simulator) and TestFlight HOT 8
- Method to get TaskUpdate of a Task HOT 4
- Single Download Progress Notification for Multiple URLs HOT 8
- [Android] Gradle MergeFailureException with compileSdkVersion 34 and Foreground Service HOT 3
- Start download from the beginning HOT 1
- Download notification do not show the progress HOT 1
- [Android] notification icon HOT 3
- Large attachment uploading takes a while HOT 2
- Build failure with `background_downloader` due to missing Kotlin plugin HOT 3
- Monthly issue metrics report for opened issues and prs
- Monthly issue metrics report for closed issues and prs
- Receive status update in background HOT 6
- Lack of Docs for `downloadBatch` HOT 1
- Upload tasks get randomly restarted on a slow Android device HOT 4
- Duplicate Task when uploading an image HOT 6
- Could not find org.jetbrains.kotlin:kotlin-serialization-compiler-plugin-embeddable:1.7.10. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from background_downloader.