image_downloader: ^0.31.0 下载时不显示错误,但不下载

发布于 2025-01-18 15:23:13 字数 2910 浏览 0 评论 0原文

因此,我正在尝试使用URL下载图像,我尝试了image_downloader软件包示例代码,但没有显示任何错误。我遇到的问题是图像不是下载,但在调试控制台上没有说什么。

Future<void> _downloadImage(
    String url, {
    AndroidDestinationType? destination,
    bool whenError = false,
    String? outputMimeType,
  }) async {
    String? fileName;
    String? path;
    int? size;
    String? mimeType;
    try {
      String? imageId;

      if (whenError) {
        imageId = await ImageDownloader.downloadImage(url,
                outputMimeType: outputMimeType)
            .catchError((error) {
          if (error is PlatformException) {
            String? path = "";
            if (error.code == "404") {
              print("Not Found Error.");
            } else if (error.code == "unsupported_file") {
              print("UnSupported FIle Error.");
              path = error.details["unsupported_file_path"];
            }
            setState(() {
              _message = error.toString();
              _path = path ?? '';
            });
          }

          print(error);
        }).timeout(Duration(seconds: 10), onTimeout: () {
          print("timeout");
          return;
        });
      } else {
        if (destination == null) {
          imageId = await ImageDownloader.downloadImage(
            url,
            outputMimeType: outputMimeType,
          );
        } else {
          imageId = await ImageDownloader.downloadImage(
            url,
            destination: destination,
            outputMimeType: outputMimeType,
          );
        }
      }

      if (imageId == null) {
        return;
      }
      fileName = await ImageDownloader.findName(imageId);
      path = await ImageDownloader.findPath(imageId);
      size = await ImageDownloader.findByteSize(imageId);
      mimeType = await ImageDownloader.findMimeType(imageId);
    } on PlatformException catch (error) {
      setState(() {
        _message = error.message ?? '';
      });
      return;
    }

    if (!mounted) return;

    setState(
      () {
        var location = Platform.isAndroid ? "Directory" : "Photo Library";
        _message = 'Saved as "$fileName" in $location.\n';
        _size = 'size:     $size';
        _mimeType = 'mimeType: $mimeType';
        _path = path ?? '';

        if (!_mimeType.contains("video")) {
          _imageFile = File(path!);
        }
        return;
      },
    );
  }

我这样称呼

,它在控制台中显示了这一点

这是包装 https://pub.dev/packages/image_downloader/example

So, i'm trying to download a image with the url, i've tried the image_downloader package example code and it didn't show any error. The issue that i'm having is that the image isn't downloading but on the debug console doesn't say anything.

Future<void> _downloadImage(
    String url, {
    AndroidDestinationType? destination,
    bool whenError = false,
    String? outputMimeType,
  }) async {
    String? fileName;
    String? path;
    int? size;
    String? mimeType;
    try {
      String? imageId;

      if (whenError) {
        imageId = await ImageDownloader.downloadImage(url,
                outputMimeType: outputMimeType)
            .catchError((error) {
          if (error is PlatformException) {
            String? path = "";
            if (error.code == "404") {
              print("Not Found Error.");
            } else if (error.code == "unsupported_file") {
              print("UnSupported FIle Error.");
              path = error.details["unsupported_file_path"];
            }
            setState(() {
              _message = error.toString();
              _path = path ?? '';
            });
          }

          print(error);
        }).timeout(Duration(seconds: 10), onTimeout: () {
          print("timeout");
          return;
        });
      } else {
        if (destination == null) {
          imageId = await ImageDownloader.downloadImage(
            url,
            outputMimeType: outputMimeType,
          );
        } else {
          imageId = await ImageDownloader.downloadImage(
            url,
            destination: destination,
            outputMimeType: outputMimeType,
          );
        }
      }

      if (imageId == null) {
        return;
      }
      fileName = await ImageDownloader.findName(imageId);
      path = await ImageDownloader.findPath(imageId);
      size = await ImageDownloader.findByteSize(imageId);
      mimeType = await ImageDownloader.findMimeType(imageId);
    } on PlatformException catch (error) {
      setState(() {
        _message = error.message ?? '';
      });
      return;
    }

    if (!mounted) return;

    setState(
      () {
        var location = Platform.isAndroid ? "Directory" : "Photo Library";
        _message = 'Saved as "$fileName" in $location.\n';
        _size = 'size:     $size';
        _mimeType = 'mimeType: $mimeType';
        _path = path ?? '';

        if (!_mimeType.contains("video")) {
          _imageFile = File(path!);
        }
        return;
      },
    );
  }

and i'm calling it like this
enter image description here

and it shows this in the console
enter image description here

this is the package
https://pub.dev/packages/image_downloader/example

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聽兲甴掵 2025-01-25 15:23:13

图像未显示在图库中

检查上面的链接,它可能对您有帮助。
您可能会发现 Image_gallery_saver 也可以用于下载您的图像,如果您仍然使用现有的软件包,那么您会提出一个与它有关的问题。

Images doesn't show in gallery

Check above link , it may helpful to you.
You may find Image_gallery_saver too for downloading your image , And if still you go with existing package then you raise a issue with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文