File-Manager icon indicating copy to clipboard operation
File-Manager copied to clipboard

Saving a file to storage by sharing it causes loss of file name and extension

Open luewolf opened this issue 2 years ago • 4 comments

Checklist

  • [x] I can reproduce the bug with the latest version.
  • [x] I made sure that there are no existing issues - open or closed - to which I could contribute my information to.
  • [x] I have read the FAQ and my problem isn't listed.
  • [x] I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
  • [x] This issue contains only one bug.
  • [x] I have read and understood the contribution guidelines.

Describe the bug

When sharing a single file that isn't a directory from any app, the file manager can be selected as destination to save the file in shared storage. However, both the file name and extension are lost when saving the file. The loss of the file extension in particular means that other programs (i.e. those that only have permissions for media files) won't be able to discover/open the file.

To Reproduce

Steps to reproduce the behavior:

  1. Go to any app that allows sharing a single file. The file manager itself will do. Open the share dialog.
  2. Look for the destination titled "File Manager", subtitle "Save..." and click on it.
  3. Select a directory to save the file at.
  4. In file manager, navigate to that directory. The file will be titled something like "1000019000" now. It will not have a file extension.

Expected behavior

Ideally, the file would keep its name and extension.

If the sharing API simply does not provide this info, file extensions can be "guessed" using a file format's magic number. This should be implemented for common file formats like zip, pdf, png, jpg, webp, gif, mp3, mp4, ogg.

luewolf avatar Jan 23 '24 22:01 luewolf

Hi devs, would you like help with this?

It seems reasonably straightforward -- modify SaveAsActivity.kt to call contentResolver.query(source, ...) and look up the relevant columns (I think MediaStore.MediaColumns.DISPLAY_NAME, and fall back to DATA; also MIME_TYPE). I'm happy to write a PR.

tom93 avatar Jan 26 '24 22:01 tom93

I'm happy to write a PR.

@tom93 When there's no needs triage label on an issue, you're free to create a PR solving it.

Aga-C avatar Jan 26 '24 22:01 Aga-C

@tom93 Are you still planning to make a PR?

matkoniecz avatar Apr 20 '24 07:04 matkoniecz

@matkoniecz I've been putting it off, but your message gave me the push I needed and I finally made PR #86 :) For people who want to test my fix without building from source, I've built an APK with the patch from my PR plus this patch which adds some debugging logs, but note that I am not a project member so you shouldn't trust me: unofficial-file-manager-pr-86-with-debug.apk.zip To view the debug logs, run adb logcat and search for lines containing "XXX".

In the end I didn't implement the fallback to the DATA column, because the DISPLAY_NAME column worked in all my tests (and there was existing code for reading the DISPLAY_NAME column).

tom93 avatar Apr 20 '24 12:04 tom93