ko2ic / image_downloader

Flutter plugin that downloads images and movies on the Internet and saves to Photo Library on iOS or specified directory on Android.
https://pub.dartlang.org/packages/image_downloader#-readme-tab-
MIT License
92 stars 116 forks source link

Can't download image from API Url (localhost) #51

Closed zgramming closed 4 years ago

zgramming commented 4 years ago

Hello, i got some problem with download image from API Url. I have Url like this http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, I can see the image but when i try download it ,my console give me infinite loop like this and my image not downloaded :

D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
D/image_downloader(21091): RequestResult(id=798, remoteUri=http://192.168.43.159/flutter-news/images/berita/92dae9b51087d930a32aff53eaded163.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader(21091): 0
Application finished.
Exited (sigterm)

My simple download code like this :

Future testingDownloadImage(String imageUrl) async {
    try {
      var imageId =
          await ImageDownloader.downloadImage('$baseURLimage/berita/$imageUrl');
      if (imageId == null) {
        print('Image Kosong');
      }
      var fileName = await ImageDownloader.findName(imageId);
      var path = await ImageDownloader.findPath(imageId);
      var size = await ImageDownloader.findByteSize(imageId);
      var mimeType = await ImageDownloader.findMimeType(imageId);
      print(imageId);
      print(fileName);
      print(path);
      print(size);
      print(mimeType);
    } catch (e) {
      print(e);
      return null;
    }
  }

Main.dart

void _testingDownloadImage(String imageUrl) async {
    var downloadImage = api.testingDownloadImage(imageUrl);
    print(downloadImage);
    if (downloadImage != null) {
      print('success');
    } else {
      print('failed');
    }
  }
 IconButton(
                                    onPressed: () => _testingDownloadImage(
                                        widget.gambarBerita),
                                    icon: Icon(Icons.save),
                                  ),

I'm already read this issue : Github Issue 400 Stackoverflow

but result is nothing,I'm mistake something ?

Btw , if i'm using default Url documentation Image Default, Everything it's ok.

wyklif commented 4 years ago

also facing this issue, however when i started building my app it was working

wyklif commented 4 years ago

i just found out that i was passing a wrong value for url, print out your url and see what you are actually passing to the downloader @zgramming

ko2ic commented 4 years ago

I tried writing the following nodejs.

var app = express();
app.get('/*.(png|bmp|jpg|jpeg)', function (req, res) {
        console.log(req.url);
        res.sendFile(path.resolve('./images/'+req.url));
    });
$ tree images
images
└── flutter.jpg

In this example project, I confirmed the operation with the following URL on Android. It works without problems.

_downloadImage("http://10.0.2.2:3000/flutter.jpg");
HTMHell commented 4 years ago

That's probably happening because you are not downloading from HTTPS. Look at: https://github.com/ko2ic/image_downloader/issues/47

ko2ic commented 4 years ago

Close it because it has been confirmed that it works without problems.

gaoobin commented 4 years ago

What is the solution, I also encountered this problem

gaoobin commented 4 years ago

Close it because it has been confirmed that it works without problems.

What is the solution, I also encountered this problem