Home > Mobile >  Uploading file with encode to byte vs without encode
Uploading file with encode to byte vs without encode

Time:11-06

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

CodePudding user response:

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.

  • Related