Skip to content
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

feat: More restrictive MIME types for better UX uploading images from Android #844

Open
1 task done
oBusk opened this issue Jun 2, 2024 · 3 comments
Open
1 task done
Labels
✨ enhancement suggestion or feature request to improve uploadthing haunted things that will likely be difficult to test / find root causes on 🙋‍♂️ help wanted

Comments

@oBusk
Copy link

oBusk commented Jun 2, 2024

Describe the feature you'd like to request

The UploadButton component creates a <input type="file"> which includes every image/* MIME in it's accept="", apparently because some OSes don't want to use image/*. Some of these mime types, causes Android to opt out of their "Cloud media app" flow, and instead of showing all images from your google Photos, to select a file instead.

File Selector Cloud media
Screenshot_20240602-131834 Screenshot_20240602-131851

I tested a small thing https://image-mime-types.vercel.app/ and it seems like all MIME types with a period in them, triggers the file selection flow intead of the cloud media flow. Which honestly sounds like a bug in Android, but you know.

I was thinking how to work around this? Do I create add one config entry for each MIME I want to support? I also tried having the key in my FileRouter to be all mime types comma separated, which builds and creates a Upload button that's correct, but API gets sad when I upload.

I also was considering writing my own component so that I can specify a more restrictive "accepts" while using the "image" file route config.

But either way, I feel like the "out of the box" experience of uploadthing should be as smooth as possible? If you create upload of images, it shoul go into the image gallery path rather than "find a file on your phone".

Describe the solution you'd like to see

I think "UploadButton" component could recieve configuration to allow us to modify the accepts, but I also think that the default when using image in your File route, should exlcude all image types with periods in them. But if UploadThing don't want to build a work-around for an android/chrome bug(?) I also think that's fair.

Additional information

I've been trying to find information about what rules trigger the "Cloud media app" on android, but I honestly can't find any.. It's a case of unfortunate mix of buzz words...

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!
@oBusk oBusk added the ✨ enhancement suggestion or feature request to improve uploadthing label Jun 2, 2024
@juliusmarminge
Copy link
Collaborator

hmm this is a weird one that I'm not quite sure how to solve in the best way... allowing overriding mime types sort of defeats the purpose of having a prebuilt component that manages the state for you, but I can see it being tempting as an escape hatch for these sort of edge cases

I also think that the default when using image in your File route, should exclude all image types with periods in them.

I don't think I agree with this one. Those mimes are valid image types, even if Android doesn't like that...

Will open this issue up for discussion and see if others have an opinion

@juliusmarminge juliusmarminge added haunted things that will likely be difficult to test / find root causes on 🙋‍♂️ help wanted labels Jun 3, 2024
@markflorkowski
Copy link
Collaborator

a potential workaround might include a configuration option in the router where you can specify an array of mime types, so that you would not have to make separate entries for each.

I could see this as another type of "magic" type for file routes:

...
 profileImage: f({
    custom: {
        mimes: ()=>[]
    },
  })
...

or as a restriction on existing magic types:

... 
  profileImage: f({
    image: {
      excludeMimes: ()=>[]
      maxFileSize: "4MB",
    },
  })
...

But either way, I feel like the "out of the box" experience of uploadthing should be as smooth as possible?

This is our north star on finding an acceptable solution here, so handling bugs in Android is "in scope" to some degree. Whatever solution we come to should not degrade the experience for everyone else though.

@oBusk
Copy link
Author

oBusk commented Jun 7, 2024

An improved syntax to be able to configure entries for multiple MIME types like that would be a very nice way to be more flexible in the configuration, but would not mean optimal use-case out-of-the-box 😞 But maybe best option is to have a good way to configure MIME and a note in docs about the implications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement suggestion or feature request to improve uploadthing haunted things that will likely be difficult to test / find root causes on 🙋‍♂️ help wanted
Projects
None yet
Development

No branches or pull requests

3 participants