fastapi-admin icon indicating copy to clipboard operation
fastapi-admin copied to clipboard

`FileUpload`'s `save_file` function returns path incorrectly on Windows with backslash separator (due to `os.path.join`)

Open nb-programmer opened this issue 1 year ago • 0 comments

Title says it all.

When using from fastapi_admin.file_upload import FileUpload and it returns the save path (endpoint to fetch the file) using prefix and filename, it joins the path using os.path.join, which is OS-dependent. This causes the filename to contain \ separated path on Windows.

Example:

upload_face = FileUpload(
    uploads_dir="./static/uploads",
    prefix="/faces",  # StaticFiles is mounted here
    filename_generator=random_filename,  # Ignore this
)
image

It just causes the backslash escape character sequence to mess up path when fetching images sometimes.

nb-programmer avatar Feb 03 '24 09:02 nb-programmer