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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Fix uploading GIF URI #45826

Closed
wants to merge 1 commit into from
Closed

Conversation

s77rt
Copy link
Contributor

@s77rt s77rt commented Jul 30, 2024

Summary:

In Android, when constructing a multipart body for a file and that file source is a uri (base64-encoded) we do the following:

  1. Decode the base64 string into bytes
  2. Create a bitmap object
  3. Compress the bitmap object as PNG into new bytes

The process does an unnecessary work (bytes -> bitmap -> bytes) and creates unexpected results e.g. a GIF file will be converted into PNG when uploaded. This PR removes the unnecessary steps (2 and 3).

Changelog:

[ANDROID] [FIXED] - Fix uploading GIF URI

Test Plan:

  1. Upload a GIF; use URI (base64-encoded)
  2. Verify that the uploaded file is a GIF
const formData = new FormData();
formData.append('photo', {
  uri: GIFURI,
  type: 'image/gif',
  name: 'photo.gif',
});

fetch(UPLOAD_URL,
{
    body: formData,
    method: "POST",
}):
Before After
Screen.Recording.2024-07-30.at.8.50.51.PM.mov
Screen.Recording.2024-07-30.at.8.58.21.PM.mov

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jul 30, 2024
@tdn120
Copy link

tdn120 commented Jul 30, 2024

Can you please take a look at #33675 and confirm the steps are unnecessary, given that context?

@s77rt
Copy link
Contributor Author

s77rt commented Jul 30, 2024

@tdn120 From that issue

I think converting the dataUri to Bitmap is necessary as there is no method that lets us convert the dataUri to inputStream directly

That's not the case. The decoded bytes can be used directly.

@facebook-github-bot
Copy link
Contributor

@tdn120 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Aug 1, 2024
@facebook-github-bot
Copy link
Contributor

@tdn120 merged this pull request in 48669af.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @s77rt in 48669af

When will my fix make it into a release? | How to file a pick request?

@s77rt
Copy link
Contributor Author

s77rt commented Aug 2, 2024

@tdn120 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants