Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] [image-manipulator] change base64 encoding options to match with other platforms #7837

Closed
jarvisluong opened this issue Apr 14, 2020 · 5 comments

Comments

@jarvisluong
Copy link
Contributor

jarvisluong commented Apr 14, 2020

This will also affect other modules which produces base64 output as well (camera, file system, ...)

馃悰 Bug Report

The base64 output from Android and iOS for the method ImageManipulator.manipulateAsync does not match given the same image.

The output does not necessary need to be exactly matched, but the way base64 output is created currently not matched. When I look at the source code of expo-image-manipulator, on Android, the output is produced by:

base64String = Base64.encodeToString(byteOut.toByteArray(), Base64.DEFAULT);

This option (Base64.DEFAULT) will produce a base64 result which will inject line termination character every 74 (maybe?) character.

on iOS:

response[@"base64"] = [imageData base64EncodedStringWithOptions:0];
):

This option will produce a base64 result which will be a long line (without line terminators)

and on web:

base64 = canvas.toDataURL('image/' + format, quality);

This method will produce a base64 result which will be a long line (without line terminators)

What we can do is to change the option on Android into:

Base64.encodeToString(byteOut.toByteArray(), Base64.NO_WRAP)

(reference:

  1. https://developer.android.com/reference/android/util/Base64#NO_WRAP
  2. https://stackoverflow.com/questions/32935783/java-different-results-when-decoding-base64-string-with-java-util-base64-vs-and
    )

Environment

Steps to Reproduce

Here is a minimal snack: https://snack.expo.io/@bankify_expo_admin/085b26

Expected Behavior

The base64 output should be the same given the same image

Actual Behavior

Reproducible Demo

@jarvisluong jarvisluong changed the title [image-manipulator] add options to customize base64 encoding [android] [image-manipulator] change base64 encoding options to match with other platforms Apr 14, 2020
@cruzach
Copy link
Contributor

cruzach commented Apr 14, 2020

Thanks for the excellent bug report @jarvisluong ! I agree that this should be consistent across all platforms

Would you like to open a PR for this change?

@jarvisluong
Copy link
Contributor Author

@cruzach Definitely, Should we change the base64 encoding for FileSystem and Camera as well?

@cruzach
Copy link
Contributor

cruzach commented Apr 14, 2020

Seems like you aren't the only one who's discovered this so that may be a good idea. I'm not sure if this would then be considered a breaking change though

@jarvisluong
Copy link
Contributor Author

jarvisluong commented Apr 14, 2020

I see that in FileSystem the encoding method is already using .NO_WRAP as here:

contents = Base64.encodeToString(buffer, 0, bytesRead, Base64.NO_WRAP);

So yes, bringing existing decoders to be the same option would be a good idea!

@cruzach
Copy link
Contributor

cruzach commented Apr 16, 2020

thanks @jarvisluong ! closed in #7841

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants