FossifyOrg / File-Manager

Easy app for managing your files without ads, respecting your privacy & security
https://www.fossify.org
GNU General Public License v3.0
643 stars 33 forks source link

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

Open luewolf opened 10 months ago

luewolf commented 10 months ago

Checklist

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.

tom93 commented 10 months ago

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.

Aga-C commented 10 months ago

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.

matkoniecz commented 7 months ago

@tom93 Are you still planning to make a PR?

tom93 commented 7 months ago

@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).