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

UploadButton returns the wrong path #3790

Closed
1 task done
AscendantAI-Robbie opened this issue Apr 8, 2023 · 12 comments · Fixed by #3782
Closed
1 task done

UploadButton returns the wrong path #3790

AscendantAI-Robbie opened this issue Apr 8, 2023 · 12 comments · Fixed by #3782
Assignees
Labels
bug Something isn't working

Comments

@AscendantAI-Robbie
Copy link

AscendantAI-Robbie commented Apr 8, 2023

Describe the bug

The wrong path is returned with and without preprocess enabled. With preprocess enabled, the path defaults to some system temporary directory. Without preprocess enabled, a dictionary is returned without enough information to derive the location of the image.

  1. These options should return the same types
  2. The correct absolute path should be returned

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

Run the UploadButton documentation

import gradio as gr

def upload_file(files):
    file_paths = [file.name for file in files]
    return file_paths

with gr.Blocks() as demo:
    file_output = gr.File()
    upload_button = gr.UploadButton("Click to Upload a File", file_types=["image", "video"], file_count="multiple")
    upload_button.upload(upload_file, upload_button, file_output)
demo.launch()

Screenshot

No response

Logs

N/A

System Info

Website documentation and

Windows10
Python3.10.6
gradio=3.24.1

Severity

blocking all usage of gradio

@AscendantAI-Robbie AscendantAI-Robbie added the bug Something isn't working label Apr 8, 2023
@xujipm
Copy link

xujipm commented Apr 9, 2023

Even the official example also has this bug, upload the file and then download it again becomes a 0k file
https://gradio.app/docs/#uploadbutton

@abidlabs
Copy link
Member

abidlabs commented Apr 9, 2023

Hi @xujipm @AscendantAI-Robbie we have a fix of this in the works in #3782

@xujipm
Copy link

xujipm commented Apr 10, 2023

Hi @xujipm @AscendantAI-Robbie we have a fix of this in the works in #3782

If I need to use this upload function urgently now, how should I operate it?

@freddyaboulton freddyaboulton self-assigned this Apr 10, 2023
@freddyaboulton
Copy link
Collaborator

I belive #3782 fixes the issue @xujipm - at least in the repro you shared.

Install this version of gradio (built from the PR) and see if it works for you!

https://gradio-builds.s3.amazonaws.com/1e6a98be6765b957b4972a14be7bffb212ac1b04/gradio-3.24.1-py3-none-any.whl
 


@AscendantAI-Robbie
Copy link
Author

This has not exactly been fixed in gradio3.25.0. The file gets uploaded to C:\Users\user\AppData\Local\Temp\randomfolder along with a temp file on each click.

There are several problems with this:

  1. If the user clears there temporary folder, this data is no longer accessible
  2. Applications should have control over their data. This means that most applications will end up copying the image into their own data management system. This results in duplicate images and a storage leak that relies on the application user periodically deleting their temporary data.

@abidlabs
Copy link
Member

Hi @AscendantAI-Robbie, I believe issue #3597 is referring to the points you've raised. We'll tackle that soon

@xujipm
Copy link

xujipm commented Apr 13, 2023

macos 13.3.1 (22E261)

I have update to gradio3.25.0 but also got a wrong ptah

Had the same problem on this version
https://gradio-builds.s3.amazonaws.com/1e6a98be6765b957b4972a14be7bffb212ac1b04/gradio-3.24.1-py3-none-any.whl

import gradio as gr
import os

def uploadf(file):
    print(file.name)
    fdir = 'uploads'
    if not os.path.exists(fdir):
        os.makedirs(fdir)
    with open(os.path.join(fdir, file.name), 'wb') as f:
        with open(file.name, 'rb') as file:
            f.write(file.read())
    return file.name


with gr.Blocks() as demo:
    fbtn = gr.File()
    result = gr.Text("Result")

    fbtn.upload(uploadf,fbtn,result)

demo.launch()
    

image

@abidlabs
Copy link
Member

Hi @xujipm sorry can you explain what the issue you are facing is?

@xujipm
Copy link

xujipm commented Apr 13, 2023

Hi @xujipm sorry can you explain what the issue you are facing is?

I upload a file on the web page, the path of the image returned by the upload network request is correct, and the file can be found in that path, but in the python script, the path returned by the upload method cannot find the file, so the code cannot obtain the image I uploaded document

@abidlabs
Copy link
Member

Ok going to reopen this issue and we'll take another look at it

@abidlabs abidlabs reopened this Apr 13, 2023
@xujipm
Copy link

xujipm commented Apr 13, 2023

Ok going to reopen this issue and we'll take another look at it

I'm very sorry, there is a bug in my code, this issue can be closed

with open(os.path.join(fdir, file.name), 'wb')  as f

os.path.join(fdir, file.name) return file.name So the content of the temp folder is overwritten to 0kb

there should be changed to

with open(os.path.join(fdir,  Path(file.name).name), 'wb')  as f

@abidlabs
Copy link
Member

Ok good to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants