Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 664
Manoj Perumarath Avatar asked Jan 27 '23 20:01

Manoj Perumarath


1 Answers

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.

like image 190
Günter Zöchbauer Avatar answered Jan 30 '23 15:01

Günter Zöchbauer