Kamil Harasimowicz Kamil Harasimowicz - 3 years ago 282
Dart Question

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

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;

My problem appears in firebase console:

enter image description here
Photo has
type instead of
. 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?


image_picker: 0.1.1
firebase_storage: 0.0.6

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download