-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving a file to storage by sharing it causes loss of file name and extension #37
Comments
Hi devs, would you like help with this? It seems reasonably straightforward -- modify SaveAsActivity.kt to call |
@tom93 When there's no |
@tom93 Are you still planning to make a PR? |
Previously, the code used the last path component of the content URI, but that isn't necessarily the filename -- it can be a numeric ID. Switch to the helper function getFilenameFromContentUri(), which uses ContentResolver to read the DISPLAY_NAME column. (If that fails, we fall back to the last component of the content URI as before, because we don't have anything better to use.) Also improve the way the MIME type is determined. Previously it was just based on the file extension. Switch to first query the ContentResolver, then try the type of the Intent (which is supposed to be set to the MIME type of the data for ACTION_SEND, but may be set to "*/*" if the type is unknown), and only then fall back to using the file extension. Fixes FossifyOrg#37.
@matkoniecz I've been putting it off, but your message gave me the push I needed and I finally made PR #86 :) 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). |
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:
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.
The text was updated successfully, but these errors were encountered: