Skip to content

Commit

Permalink
Fix putMediaBytes file conversion in android
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuk4ze committed Aug 18, 2023
1 parent 727ca33 commit f209d96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android {
}

dependencies {
implementation 'org.apache.commons:commons-imaging:1.0-alpha3'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.0.0'
}
Expand Down
7 changes: 6 additions & 1 deletion android/src/main/java/studio/midoridesign/gal/GalPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import java.io.ByteArrayInputStream;
import java.util.UUID;

import org.apache.commons.imaging.ImageFormat;
import org.apache.commons.imaging.Imaging;

public class GalPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware,
PluginRegistry.RequestPermissionsResultListener {
private static final String PERMISSION = Manifest.permission.WRITE_EXTERNAL_STORAGE;
Expand Down Expand Up @@ -130,8 +133,10 @@ private void putMedia(Context context, String path, String album, boolean isImag

private void putMediaBytes(Context context, byte[] bytes, String album)
throws IOException, SecurityException {
ImageFormat imageFormat = Imaging.guessFormat(bytes);
String extension = "." + imageFormat.getDefaultExtension().toLowerCase();
try (InputStream in = new ByteArrayInputStream(bytes)) {
writeData(context, in, true, ".jpg", album);
writeData(context, in, true, extension, album);
}
}

Expand Down

0 comments on commit f209d96

Please sign in to comment.