chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

Missing file suffix when uploading xlsx file

Open Valdanitooooo opened this issue 1 year ago • 1 comments

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

Valdanitooooo avatar Sep 27 '24 09:09 Valdanitooooo

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.

dosubot[bot] avatar Sep 27 '24 09:09 dosubot[bot]

same but in my development environment (windows server 2012) it can get suffix, weird

Version: 1.2.0 OS: centos7 and windows server 2019

EcoleKeine avatar Oct 10 '24 09:10 EcoleKeine

but in my development environment (windows server 2012) it can get suffix, weird

Me too. My macos development environment is fine, but using docker containers in the production environment may cause this issue.

My current solution is to check if the file path has a suffix, and then add the suffix from the file name to the file path.

Valdanitooooo avatar Oct 10 '24 09:10 Valdanitooooo

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Jul 25 '25 23:07 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Aug 02 '25 02:08 github-actions[bot]