简体   繁体   中英

Convert application/octet-stream to image/jpeg/png in flutter?

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

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');

or pass metadata

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM