Allow use of file extensions in gr.File in iOS #8905
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This one is a yet another annoying iOS issue. We accept file extensions (alongside
image/*
etc, this is fine) in thefile_types
attribute ingr.File
, but in iOS these file extensions won't actually work, and will grey out all the options. We could process each and every possible file extension that might be used and get the corresponding mime type but I don't like this approach.I've opted to validate the file after the file has been selected, showing an error with the expected file type. I'd hope that the expected file types would be displayed either in the info text by the user or some point soon in the actual upload area which I think we've discussed before (I should raise an issue for this, it would improve UX).
Here's how the overall logic looks in the File component now:
Test example:
Uploading a .las file when
file_types=['.las']
Closes: #7930
Caniuse reference
![Screenshot 2024-07-25 at 18 44 40](https://private-user-images.githubusercontent.com/15165908/352218795-c89af8b0-f424-42f9-a63a-95aa8375047d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzMzk2OTIsIm5iZiI6MTczOTMzOTM5MiwicGF0aCI6Ii8xNTE2NTkwOC8zNTIyMTg3OTUtYzg5YWY4YjAtZjQyNC00MmY5LWE2M2EtOTVhYTgzNzUwNDdkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDA1NDk1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzOWM4NzQzY2I5YjBhYTFjOWFmM2RkYTBjMDY0YmM3ZDc3ODRkMzUxZjNhODUyNmNmMWI2ZmM5ZjIwMTAwM2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0._D_HFGVNAiE3CPY-WZvMAnr0OmDeD2kzl9eY28K0HB4)
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh