【问题标题】:Cannot download file from url?无法从 url 下载文件?
【发布时间】:2021-05-17 16:15:04
【问题描述】:

我只想使用flutter_downloader包从一个url下载一个文件,我的代码很简单:

  String url =  await _databaseService.getContractDownloadUrl();
  await DownloadHelper.download(url);

该文件是来自维基百科的图片,仅供测试:https://upload.wikimedia.org/wikipedia/commons/e/e4/GatesofArctic.jpg

当我单击我的按钮时,比较“已启动”的通知,但随后应用程序崩溃并失败。这是我的控制台:

W/WM-WorkSpec(17674): Backoff delay duration less than minimum value
D/DownloadWorker(17674): DownloadWorker{url=https://upload.wikimedia.org/wikipedia/commons/e/e4/GatesofArctic.jpg,filename=null,savedDir=/sdcard/download/,header=,isResume=false
D/DownloadWorker(17674): Update notification: {notificationId: 10, title: https://upload.wikimedia.org/wikipedia/commons/e/e4/GatesofArctic.jpg, status: 2, progress: 0}
D/DownloadWorker(17674): Open connection to https://upload.wikimedia.org/wikipedia/commons/e/e4/GatesofArctic.jpg
I/System.out(17674): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(17674): (HTTPLog)-Static: isSBSettingEnabled false
D/DownloadWorker(17674): Content-Type = image/jpeg
D/DownloadWorker(17674): Content-Length = 821472
D/DownloadWorker(17674): Charset = null
D/DownloadWorker(17674): Content-Disposition = null
D/DownloadWorker(17674): fileName = GatesofArctic.jpg
D/DownloadWorker(17674): Update too frequently!!!!, but it is the final update, we should sleep a second to ensure the update call can be processed
I/flutter (17674): Fatal: could not find callback
F/flutter (17674): [FATAL:flutter/fml/message_loop.cc(78)] Check failed: loop != nullptr. MessageLoop::EnsureInitializedForCurrentThread was not called on this thread prior to message loop use.
F/libc    (17674): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 18686 (1.raster), pid 17674 (ia.tiParcheggio)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/beyond1lteeea/beyond1:11/RP1A.200720.012/G973FXXU9FUBD:user/release-keys'
Revision: '26'
ABI: 'arm64'
Timestamp: 2021-05-17 17:41:59+0200
pid: 17674, tid: 18686, name: 1.raster  >>> com.resmedia.tiParcheggio <<<
uid: 10368
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: '[FATAL:flutter/fml/message_loop.cc(78)] Check failed: loop != nullptr. MessageLoop::EnsureInitializedForCurrentThread was not called on this thread prior to message loop use.
'
    x0  0000000000000000  x1  00000000000048fe  x2  0000000000000006  x3  0000007c1d830570
    x4  0000007f973c1000  x5  0000007f973c1000  x6  0000007f973c1000  x7  0000000005d82e92
    x8  00000000000000f0  x9  0000007f93e769e8  x10 ffffff80fffffbdf  x11 0000000000000001
    x12 0000007c1d82f380  x13 00000000000000b0  x14 0000000000000000  x15 0000263e909d145c
    x16 0000007f93f0fc80  x17 0000007f93ef18b0  x18 0000007c0c0a2000  x19 00000000000000ac
    x20 000000000000450a  x21 00000000000000b2  x22 00000000000048fe  x23 00000000ffffffff
    x24 0000007d3f92f9e8  x25 0000007c1d831000  x26 0000000000000001  x27 000000000000005d
    x28 0000000000000001  x29 0000007c1d8305f0
    lr  0000007f93ea49cc  sp  0000007c1d830550  pc  0000007f93ea49fc  pst 0000000000000000
backtrace:
      #00 pc 000000000004e9fc  /apex/com.android.runtime/lib64/bionic/libc.so (abort+180) (BuildId: 60535ec972fea6eddd93daf23db05208)
      #01 pc 00000000012ef1b8  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #02 pc 00000000013127cc  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #03 pc 0000000001312eec  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #04 pc 0000000001315810  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #05 pc 0000000001315848  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #06 pc 00000000013481c8  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #07 pc 0000000001352bb4  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #08 pc 0000000001313298  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #09 pc 00000000013183d0  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #10 pc 000000000001a064  /system/lib64/libutils.so (android::Looper::pollInner(int)+916) (BuildId: f7e62c203d9645802caa9325d785d7c9)
      #11 pc 0000000000019c68  /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+112) (BuildId: f7e62c203d9645802caa9325d785d7c9)
      #12 pc 0000000000012d3c  /system/lib64/libandroid.so (ALooper_pollOnce+100) (BuildId: 24b6586fe44ab8ec8b04f4f5f65be25d)
      #13 pc 0000000001318358  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #14 pc 00000000013131e0  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #15 pc 000000000131613c  /data/app/~~yKLi-g8H3pUVlRavTcZiwA==/com.resmedia.tiParcheggio-81kQOxG6670OkYk5KC0evQ==/lib/arm64/libflutter.so (BuildId: 3beb04d15ca0dce5daadd727726b8965ef57468d)
      #16 pc 00000000000b10e8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64) (BuildId: 60535ec972fea6eddd93daf23db05208)
      #17 pc 0000000000050a58  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 60535ec972fea6eddd93daf23db05208)
Lost connection to device.

在我的清单中我有这个:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

这个(不管有没有它都不起作用):

 <provider
            android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
            android:authorities="${applicationId}.flutter_downloader.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

我正在使用 Flutter 2.0.6。难道我做错了什么?你有其他选择吗?

提前致谢

【问题讨论】:

  • 有什么理由不使用dart:io的普通Http模块?
  • 尝试执行flutter clean,然后执行flutter pub get,然后再次运行该应用程序。如果它仍然不起作用,则可能是包错误,如报告here

标签: flutter


【解决方案1】:

也许和这篇文章有关?

Download file from url, save to phones storage

这是上面链接中有用的代码 sn-p 之一

final taskId = await FlutterDownloader.enqueue(
  url: 'your download link',
  savedDir: 'the path of directory where you want to save downloaded files',
  showNotification: true, // show download progress in status bar (for Android)
  openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2016-07-23
    • 1970-01-01
    • 2016-05-05
    • 2012-06-18
    相关资源
    最近更新 更多