在flutter中将application/octet-stream转换为image/jpeg/png? [英] Convert application/octet-stream to image/jpeg/png in flutter?

查看:414
本文介绍了在flutter中将application/octet-stream转换为image/jpeg/png?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was trying to upload image to Firebase Store using Imagepicker library,

但是在控制台中,由于图像不可见,因此将格式显示为application/octet-stream.上传时,是否有任何方法可以将这种格式转换为dart中的图像.

But in console it's showing the format as application/octet-stream because of that the image is not visible. Is there any possible way to convert that format to image in dart itself while uploading.

推荐答案

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

Either pass a file extension to the file name when you upload

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

添加文件元数据

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

Add File Metadata

When uploading a file, you can also specify metadata for that file. This metadata contains typical file metadata properties such as name, size, and contentType (commonly referred to as MIME type). Cloud Storage automatically infers the content type from the file extension where the file is stored on disk, but if you specify a contentType in the metadata it will override the auto-detected type. If no contentType metadata is specified and the file doesn't have a file extension, Cloud Storage defaults to the type application/octet-stream. More information on file metadata can be found in the Use File Metadata section.

这篇关于在flutter中将application/octet-stream转换为image/jpeg/png?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆