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

Allow use of file extensions in gr.File in iOS #8905

Merged
merged 3 commits into from
Jul 29, 2024

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Jul 25, 2024

Description

This one is a yet another annoying iOS issue. We accept file extensions (alongside image/* etc, this is fine) in the file_types attribute in gr.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:

filetype Input accept_file_types File Picker Behavior Post-Upload Validation
['.csv', '.doc'] ".csv, .doc" Allows all files Yes, filters to .csv and .doc
'.csv' ".csv" Allows all files Yes, filters to .csv
'file/*' "*" Allows all files No
['image/', 'text/'] "image/, text/" Shows image and text files No
'image/*' "image/*" Shows image files No

Test example:

Uploading a .las file when file_types=['.las']

Closes: #7930

Caniuse reference
Screenshot 2024-07-25 at 18 44 40

🎯 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

  1. 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

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 25, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website building...
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/76544598acda5ac52426bb7a1343e39d520f6fb9/gradio-4.39.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@76544598acda5ac52426bb7a1343e39d520f6fb9#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/76544598acda5ac52426bb7a1343e39d520f6fb9/gradio-client-1.4.0.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 25, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/upload patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Allow use of file extensions in gr.File in iOS

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

Copy link
Collaborator

@dawoodkhan82 dawoodkhan82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code lgtm! Thanks for adding this. I couldn't test on iOS, but trusting it works.I think having the error for now should be good enough until we refactor the file upload Ui to include more context.

@hannahblair hannahblair merged commit 4b14ea8 into main Jul 29, 2024
12 checks passed
@hannahblair hannahblair deleted the file-extension-upload-ios branch July 29, 2024 18:24
This was referenced Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.las file cann't be uploaded in Gradio app in iPhone OS
3 participants