Skip to content

os.path and pathlib fail to parse fake paths of files uploaded via <input type="file"> #2419

@jolaf

Description

@jolaf

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

When <input type="file"> is used to upload a file, its true path is hidden, and C:\fakepath\ is prepended to file name instead, see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file#value

This logic, specified for JS, works well enough for PyScript, but when trying to parse the returned path by standard Python path libraries, os.path and pathlib.Path, both of them fail to process it correctly.

To reproduce, see https://jolaf.pyscriptapps.com/basename-issue/latest/
(just upload any small file)

Image

What browsers are you seeing the problem on? (if applicable)

Chrome

Console info

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    3rd partyErrors coming from foreign projects we either enable or rely onwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions