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

FilePicker upload fails if original filename is modified #5037

Open
ndonkoHenri opened this issue Mar 6, 2025 · 0 comments · May be fixed by #5045
Open

FilePicker upload fails if original filename is modified #5037

ndonkoHenri opened this issue Mar 6, 2025 · 0 comments · May be fixed by #5045
Assignees
Labels
bug Something isn't working controls feature request Suggestion/Request for additional feature
Milestone

Comments

@ndonkoHenri
Copy link
Contributor

Discussed in #5029

Originally posted by amgartendev March 5, 2025

Question

I'm experiencing an issue with FilePickerUploadFile. When I use file.name as the filename, everything works perfectly. However, if I modify the filename, even with a simple name like "hey.jpg", the upload fails. It does nothing.

I didn't find anything in the documentation regarding this issue or how the filename should be passed. I assume the filename must be exactly the same as on the user's computer.

The problem with this is that I'm creating a web app where users can upload multiple images, and I'm trying to rename the file using a format like DATETIME_USER-ID.EXTENSION to avoid conflicts with other images that may have the same name, even if I separate each user's files into individual folders in the uploads directory.

For example:
Original Filename: image.jpg
Renamed Filename: 20250304_123.jpg

I tried uploading the image first, regardless of its filename, and then modifying it later. However, once the image is uploaded, it automatically replaces the previous version.

Code sample

def handle_file_selection(e: ft.FilePickerResultEvent) -> None:
    if e.files:
        file = e.files[0]
        
        upload_datetime = datetime.now().strftime('%Y%m%d%H%M%S')
        ext = file.name.split(".")[-1] if "." in file.name else "bin"
        filename = f"{upload_datetime}_{self.user_uid}.{ext}"
        
        upload_url = self.page.get_upload_url(filename, 60)
        uploader = [
            ft.FilePickerUploadFile(
                name=filename,
                upload_url=upload_url
            )
        ]

        file_picker.upload(uploader)

Error message

No error message
@ndonkoHenri ndonkoHenri added controls feature request Suggestion/Request for additional feature labels Mar 6, 2025
@ndonkoHenri ndonkoHenri self-assigned this Mar 6, 2025
@ndonkoHenri ndonkoHenri added this to the Flet v0.27.6 milestone Mar 6, 2025
@ndonkoHenri ndonkoHenri added the bug Something isn't working label Mar 6, 2025
@ndonkoHenri ndonkoHenri moved this from 🆕 New to 👀 In review in Flet Development Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working controls feature request Suggestion/Request for additional feature
Projects
Status: 👀 In review
Development

Successfully merging a pull request may close this issue.

2 participants