hui-z / image_gallery_saver

flutter中用于保存图片到相册的Plugin
MIT License
271 stars 346 forks source link

MIME type error #268

Closed guolingege closed 11 months ago

guolingege commented 11 months ago

console log:

[log] PlatformException(error, MIME type application/octet-stream cannot be inserted into content://media/external/images/media; expected MIME type under image/*, null, java.lang.IllegalArgumentException: MIME type application/octet-stream cannot be inserted into content://media/external/images/media; expected MIME type under image/*
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    at android.content.ContentProviderProxy.insert(ContentProviderNative.java:557)
    at android.content.ContentResolver.insert(ContentResolver.java:2193)
    at android.content.ContentResolver.insert(ContentResolver.java:2155)
    at com.example.imagegallerysaver.ImageGallerySaverPlugin.generateUri(ImageGallerySaverPlugin.kt:99)
    at com.example.imagegallerysaver.ImageGallerySaverPlugin.saveFileToGallery(ImageGallerySaverPlugin.kt:206)
    at com.example.imagegallerysaver.ImageGallerySaverPlugin.onMethodCall(ImageGallerySaverPlugin.kt:60)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:322)
    at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(DartMessenger.java:0)
    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(R8$$SyntheticClass:0)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
)

This is a image file downloaded from aws s3 storage, with plugins CachedNetworkImage and flutter_cache_manager:

          final cache = cni.CachedNetworkImage(imageUrl: url).cacheManager;
          final manager = cache ?? fcm.DefaultCacheManager();
          final io.File file = await manager.getSingleFile(url);
          await ImageGallerySaver.saveFile(file.path);

The exception throws when executing saveFile(file.path)

guolingege commented 11 months ago

emmm, I have resolved it by renaming or copying the downloaded cache file, to a new path with appending file type suffix such as .webp is OK