Looked into this and this seems to be a problem with how files are attached on Android rather than the code that shares attachments. For instance, I believe it should work correctly for attachments that were created on desktop and synced to Android.
It also works for attachments created by sharing to Joplin.