BigImageViewer icon indicating copy to clipboard operation
BigImageViewer copied to clipboard

android 10 保存图片失败,android 10会将图片mime type识别成/octet-stream,导致保存失败

Open crzaycat opened this issue 5 years ago • 11 comments

android 10 保存图片失败,android 10会将图片mime type识别成/octet-stream,导致保存失败 errlog

图片测试地址:https://cdn.cfesport.com//attachment/2019/11/07eba2e80aae.com/large/pgc-image/3f23c2de986540609e9846f233c3ee23?imageView2/0/h/700/q/80

crzaycat avatar Nov 08 '19 02:11 crzaycat

PR is welcome!

Piasy avatar Nov 08 '19 04:11 Piasy

This issue has been fixed in the latest version(v1.6.5), but not completely: contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, mCurrentImageFile.getName()); glide-cached file's name doesn't have "jpg" extension, This will cause the saved file not to be found in the system album. Suggest to check file extension before save. @Piasy

moodcal avatar May 15 '20 09:05 moodcal

I verified that it worked fine on Pixel, which device are you using?

Piasy avatar May 15 '20 11:05 Piasy

My device is HUAWEI P20 pro (Android 10), the saved file (without .jpg extension) can be found in file system, but not invisible in system Gallery, also can't be imported in app (e.g. WeChat). if the file is appended the ".jpg", everything is solved

moodcal avatar May 16 '20 05:05 moodcal

How about save an image in png or gif format? @moodcal

Piasy avatar May 16 '20 09:05 Piasy

I have tested a gif file on my device(P20Pro), not working correctly(the saved file is treated as jpeg, no animation, but can be animated when imported in WeChat), so the format detection should be done before appending the extension.

moodcal avatar May 17 '20 03:05 moodcal

Yeah, that's true. It worked on Google Photos when I tested on Pixel, so I didn't add that logic. Looks like necessary now.

My idea is parsing file header, but not sure if common formats have such header.

BTW, PR is welcome!

Piasy avatar May 17 '20 08:05 Piasy

A simple solution is to use the mUri's extension directly :-)

moodcal avatar May 18 '20 00:05 moodcal

That's very easy to break, many social media don't have extension in their image url.

Piasy avatar May 18 '20 03:05 Piasy

Yeah, but it's understandable to keep the same extension as the original file

moodcal avatar May 18 '20 05:05 moodcal

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:170) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) at android.content.ContentProviderProxy.insert(ContentProviderNative.java:481) at android.content.ContentResolver.insert(ContentResolver.java:1828) at android.provider.MediaStore.createPending(MediaStore.java:616) at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:1736) at com.github.piasy.biv.view.BigImageView.saveImageIntoGallery(:2)

gongshoudao avatar Aug 17 '20 14:08 gongshoudao