Skip to content

Commit

Permalink
no need to save the image locally
Browse files Browse the repository at this point in the history
  • Loading branch information
hetanthakkar committed Apr 5, 2022
1 parent 9f1fa91 commit 648a001
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public static boolean isGzipEncoding(@Nullable final String encodingType) {
if (fileContentUri.getScheme().startsWith("http")) {
return getDownloadFileInputStream(context, fileContentUri);
}

if (fileContentUriStr.startsWith("data:")) {
byte[] decodedDataUrString = Base64.decode(fileContentUriStr.split(",")[1], Base64.DEFAULT);
Bitmap bitMap = BitmapFactory.decodeByteArray(decodedDataUrString, 0, decodedDataUrString.length);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream inputStream = new ByteArrayInputStream(bytes.toByteArray());
return inputStream;
}

return context.getContentResolver().openInputStream(fileContentUri);
} catch (Exception e) {
FLog.e(ReactConstants.TAG, "Could not retrieve file for contentUri " + fileContentUriStr, e);
Expand Down

0 comments on commit 648a001

Please sign in to comment.