【问题标题】:Convert application/octet-stream to image/jpeg/png in flutter?在颤动中将应用程序/八位字节流转换为图像/jpeg/png?
【发布时间】:2019-06-15 14:37:38
【问题描述】:

我正在尝试使用 Imagepicker 库将图像上传到 Firebase 商店,

但在控制台中,它显示格式为 application/octet-stream,因为图像不可见。上传时是否有任何可能的方法将该格式转换为飞镖本身的图像。

【问题讨论】:

    标签: ios firebase dart flutter firebase-storage


    【解决方案1】:

    上传时将文件扩展名传递给文件名

    FirebaseStorage.instance
            .ref()
            .child(path)
            .child('image.jpg');
    

    或传递元数据

    FirebaseStorage.instance
            .ref()
            .child(path)
            .child('image');
    imageStore.putFile(file, StorageMetadata(contentType: 'image/jpeg'));
    

    https://firebase.google.com/docs/storage/web/upload-files#add_file_metadata

    添加文件元数据

    上传文件时,还可以指定元数据 对于那个文件。此元数据包含典型的文件元数据属性 如名称、大小和内容类型(通常称为 MIME 类型)。 Cloud Storage 会自动从 文件存储在磁盘上的文件扩展名,但如果您指定 元数据中的 contentType 它将覆盖自动检测到的类型。 如果没有指定 contentType 元数据并且文件没有 文件扩展名,云存储默认类型 应用程序/八位字节流。有关文件元数据的更多信息可以 在使用文件元数据部分中找到。

    【讨论】:

      猜你喜欢
      • 2016-09-27
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-09
      • 2011-08-22
      • 1970-01-01
      • 2022-08-20
      相关资源
      最近更新 更多