-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
Introduce media_type parameter for ui.download
#2494
Conversation
Just a small note and I can add this myself if it's too much work, but I think it would make sense to add some typo-proofing here by constraining |
Thanks for the suggestion, @iron3oxide! |
Fastapi uses strings for media_type argument in its StreamingResponse. |
My goodness, I had no idea that there were this many media types (even though arguably 99% seem somewhat obscure). I see three options:
|
Regarding option 2: My experience is that a function like Option 3 sounds pretty cumbersome, to be honest. So I tend towards FastAPI's solution with a plain string. In the end it's a rather advance feature. Usually you can specify a filename and let the browser infer the media type, covering most simple cases. And if you really need "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" as in #2491 (comment), you probably know what you're doing. |
@falkoschindler Agreed, here's a fourth solution though: I'm fine with putting this aside though and going with strings as it's not a big gripe, more a personal preference. |
@iron3oxide Using the mimetypes module for a collection of relevant media types is an interesting approach. But let's keep it simple for now and use a plain |
As requested in #2491, this PR allows to specify the media type when using
ui.download
.Can be tested with the following snippet:
Chrome will automatically create a random file name with the extensions "txt" and "html", respectively.