android - Android无法识别Flutter App下载的图像

标签 android file flutter dart client

Android Flutter应用程序从另一部Android手机上的服务器下载图像。下载后,电话画廊或文件浏览器无法打开或查看文件。但是,当由十六进制编辑器检查时,下载的文件和原始文件是精确的副本,并且当导入到Windows时,“图像查看器”可以查看“损坏的”下载文件。我在文件之间发现的唯一区别是Windows检查的元数据。这可能是什么原因?

Android服务器上的原始文件:

在Android客户端上下载的文件:

这是我用来从Uint8list创建文件的代码:

  Future<File> downloadFileAndroid(Uint8List fileBytes, String fileName) async{

    var dir = await getExternalStorageDirectory();
    File photoFile;

    var photoDirectory = await Directory(dir.path + "/Downloader").create(recursive: true);
    photoFile = await new File(photoDirectory.path + "/" + fileName).create();
    if(await photoFile.exists()){
      await photoFile.writeAsBytes(fileBytes);// also tried flush: true
      print("Created file and it exists");
    } else {
      print("Error: tried to create file but it doesnt exist");
    }
}

最佳答案

从互联网上下载图像并为其设置png扩展时,我遇到了这个问题。在文件名上使用扩展名通常会导致此错误。考虑使用https://pub.dev/packages/image_downloader通过示例代码中的默认功能下载图像。使用默认选项时,扩展名不是由编码者决定的,而是由它自己决定的。

关于android - Android无法识别Flutter App下载的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57139665/

相关文章:

java - 图像在横向模式下被拉伸(stretch)

linux - 在日志文件中与脚本 shell (linux 批处理)和重定向融洽相处

file - 这个powershell脚本是找到所有者然后更改所有者的好方法吗

flutter - 测试 block 事件类型 'Null' 不是 type 的子类型

android - 如何在 Android 中使用 OnGestureListener 检测捏缩放事件?

android,主屏幕上的网络应用程序图标而不是通用图标,apple touche 图标 : apple-touch-icon-precomposed

flutter - AlertDialog 没有被调用 onPressed

flutter - 将事件添加到 table_calendar

android - 选择输入文本字段时如何删除android中的边框?

c - 添加分数的程序不会从 C 的每一行中获取?