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

5,950

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.

Share:
5,950
Manoj Perumarath
Author by

Manoj Perumarath

ചവറു പോലെ എഴുതുന്നത് എനിക്ക് ഇഷ്ടമല്ല ! Hey there, if you have found my answers helpful you can buy me a coffee! Currently, Senior Mobile Developer at Emvigo Technologies, Kaloor, Ernakulam, Kerala.

Updated on December 08, 2022

Comments

  • Manoj Perumarath
    Manoj Perumarath over 1 year

    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.