Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uploading file with encode to byte vs without encode

I just discovered something new, so in my work place im uploading image to the server by api endpoint that prepared by my partner i just have to encode the image file that i pick from image_picker and encode it to base64Encode then i put it in the body parameter

 Future toBytes({image}) async {
  var xFile = await image;
  var path = xFile.path;
  var imageBytes = await File(path).readAsBytes();
  var base64Image = base64Encode(imageBytes);
  return base64Image;
}

but just recently i found that in firebase_storage it can upload the file without need to encode base64

var ref = FirebaseStorage.instance
          .ref()
          .child('user_image')
          .child(authResult.user.uid + '.jpg');

          await ref.putFile(image).onComplete;

so the question is what is the different between these two method? can i upload image to every api without converting it to bytes or is it just in firebase_storage? i have not tried it yet to upload the image file without converting it to base64 except firebase_storage because it’s quite troublesome to modify the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I imagine that they are trying to store the image in firestore rather than in firebase storage since converting to base64 is a way to use binary data in primarily ASCII systems (firestore). I think what you should consider doing is asking your partner what their decision is here and how it affects your overall design of your product. They may have an intention not explicitly stated and chose base64 encoding of the image data for a specific purpose. Having that discussion would be a good first step.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading