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

Missing file suffix when uploading xlsx file #1380

Open
Valdanitooooo opened this issue Sep 27, 2024 · 1 comment
Open

Missing file suffix when uploading xlsx file #1380

Valdanitooooo opened this issue Sep 27, 2024 · 1 comment
Labels
bug Something isn't working needs-triage

Comments

@Valdanitooooo
Copy link

Describe the bug
Missing file suffix when uploading xlsx file.

To Reproduce
Steps to reproduce the behavior:

I have uploaded a txt and an xlsx file.
This is my .files directory, bcb2b22f-6611-454d-aa3a-d6b03efc993f without xlsx suffix

.files/2338edc8-8e23-4701-ab94-bf4d0af6d46f:
bcb2b22f-6611-454d-aa3a-d6b03efc993f

.files/8e3e3e72-2496-4c8f-8993-4d9364e00ca7:
9665481e-8836-40d3-95e1-777b83ed03a1.txt

Expected behavior
The suffix of the xlsx file is retained after uploading

Desktop (please complete the following information):

  • Browser [chrome]

Additional context

pip show chainlit
Name: chainlit
Version: 1.1.402
@dosubot dosubot bot added the bug Something isn't working label Sep 27, 2024
Copy link

dosubot bot commented Sep 27, 2024

Hey @Valdanitooooo! I'm here to help you with any bugs or questions you have. Let's figure this out together!

The suffix of the xlsx file might be missing after uploading in the .files directory because the file.name attribute is used directly to create the file_path. If file.name does not include the suffix, the saved file will also lack the suffix.

Here is the relevant code snippet:

file_path = f"./tmp/{file.name}"

To ensure the suffix is included, you should verify that file.name contains the correct suffix when the file is uploaded. If it does not, you may need to manually append the suffix based on the file.type.

For example:

if not file.name.endswith('.xlsx') and file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
    file_path = f"./tmp/{file.name}.xlsx"
else:
    file_path = f"./tmp/{file.name}"

This way, you ensure that the .xlsx suffix is included in the file path when saving the file [1].

To continue talking to Dosu, mention @dosu.

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

No branches or pull requests

1 participant