Kamil Harasimowicz
Kamil Harasimowicz

Reputation: 4994

Flutter & Firebase: Send File as Image

I want to send photo selected by user in my app to Firebase Storage. I have a simple class with property _imageFile which is set like this:

File _imageFile;

_getImage() async {
    var fileName = await ImagePicker.pickImage();
    setState(() {
        _imageFile = fileName;
    });
}

after that I send photo like with this code:

final String rand1 = "${new Random().nextInt(10000)}";
final String rand2 = "${new Random().nextInt(10000)}";
final String rand3 = "${new Random().nextInt(10000)}";
final StorageReference ref = FirebaseStorage.instance.ref().child('${rand1}_${rand2}_${rand3}.jpg');
final StorageUploadTask uploadTask = ref.put(_imageFile);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
print(downloadUrl);

My problem appears in firebase console:

enter image description here Photo has application/octet type instead of image/png. Is there any way to fix that? Or maybe is it a good behaviour and I should not care here about types? What about downloading this photo?

My dependencies:

image_picker: 0.1.1
firebase_storage: 0.0.6

Upvotes: 2

Views: 1086

Answers (1)

Collin Jackson
Collin Jackson

Reputation: 116738

The firebase_storage plugin does not currently have an API for specifying metadata of the uploaded file. If you wanted to add this, it would be fairly straightforward and you could send us a pull request. However, there's nothing wrong with application/octet-stream; it is a general mime type for binary files that should render fine in most situations.

Upvotes: 3

Related Questions