0

I try to download a image from a website with the help of flutter_downloader. The download fails everytime immediately after starting. I dont know why.

I tried to keep the code as small as possible so somethings are missing but they arent important for my problem This is my code:

int progress = 0; 
ReceivePort receivePort = ReceivePort(); 

@override 
void initState() { 
  IsolateNameServer.registerPortWithName(receivePort.sendPort, "downloadingvideo");
  receivePort.listen((dynamic data) { 
    String id = data[0]; 
    DownloadTaskStatus status = 
    data[1]; int progress = data[2]; 
    print("Id: ${id}, Status: ${status}, Progress: ${progress},");
  }); 
  FlutterDownloader.registerCallback(downloadCallback); 
  // TODO: implement initState 
  super.initState(); 
} 
@override 
void dispose() { 
  IsolateNameServer.removePortNameMapping("downloadingvideo"); 
  super.dispose(); 
} 
static downloadCallback(String id, DownloadTaskStatus status, int progress){ 
  final SendPort sendPort = IsolateNameServer.lookupPortByName("downloadingvideo")!; 
  sendPort.send([id, status, progress]); 
} 
void _download(String url, String title) async { 
  final status = await Permission.storage.request(); 
  if(status.isGranted){ 
    final externalDir = await getExternalStorageDirectory(); 
    final id = await FlutterDownloader.enqueue( 
      url: url, savedDir: externalDir!.path, 
      fileName: title, 
      showNotification: true, 
      openFileFromNotification: true, 
      saveInPublicStorage: true,
    ); 
} else{ 
  print("Permission denied!"); 
} 
} 
@override 
Widget build(BuildContext context) { 
  return Center( 
    child: Container( 
      child: FlatButton( 
        onPressed: () {  
           _download("https://www.bergfreunde.de/out/pictures/promo/bs-teaser_y22_1.jpg", "name.png"); 
        }, 
      child: Text("Download"), 
     ), 
    ) 
   ); 
  } 
} 

This is the new error I get:

W/System.err(21506): java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.musicanywhere_app.flutter_downloader.provider 
W/System.err(21506):    at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:662) 
W/System.err(21506):    at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:635) 
W/System.err(21506):    at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:441) 
W/System.err(21506):    at vn.hunghd.flutterdownloader.IntentUtils.buildIntent(IntentUtils.java:23) 
W/System.err(21506):    at vn.hunghd.flutterdownloader.IntentUtils.validatedFileIntent(IntentUtils.java:35) 
W/System.err(21506):    at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:441) 
W/System.err(21506):    at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:235) 
W/System.err(21506):    at androidx.work.Worker$1.run(Worker.java:86) 
W/System.err(21506):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
W/System.err(21506):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
W/System.err(21506):    at java.lang.Thread.run(Thread.java:923) 
I/WM-WorkerWrapper(21506): Worker result FAILURE for Work [ id=54727eb0-aa34-4bc5-94fd-558debd43804, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]

Thanks for your help.

FatCat
  • 23
  • 7

1 Answers1

1

The error in your stack trace reads:

java.net.MalformedURLException: no protocol: musikschulemarsulm.de/static/css/marsheader_white_smal.png

And in your code you have:

_download("musikschulemarsulm.de/static/css/marsheader_white_smal.png", "name.png");

There needs to be a protocol for the url you are giving for the image.

You are either missing http or https from the url.

_download("https://musikschulemarsulm.de/static/css/marsheader_white_smal.png", "name.png");
tomerpacific
  • 4,704
  • 13
  • 34
  • 52