Open RichardFans opened 3 weeks ago
Hey @RichardFans, I'm here to help you with bug fixes, questions, and becoming a contributor. Let's squash those bugs together! 🐛
To address the issue with .docx
files saved by WPS being reported as an unsupported file type, you can modify the getFileExtension
method to handle cases where the mime type might not be correctly identified. Here's an adjusted version of the method:
export const getFileExtension = (fileName: string, fileMimetype: string) => {
if (fileMimetype) {
const extension = mime.getExtension(fileMimetype);
if (extension) {
return extension;
}
}
if (fileName) {
const fileNamePair = fileName.split('.');
const fileNamePairLength = fileNamePair.length;
if (fileNamePairLength > 1) {
const extension = fileNamePair[fileNamePairLength - 1];
// Add a specific check for .docx files saved by WPS
if (extension.toLowerCase() === 'docx') {
return 'docx';
}
return extension;
}
}
return '';
}
This modification ensures that if the mime type does not provide a valid extension, the function will fall back to checking the file name, specifically handling .docx
extensions [1].
To continue talking to Dosu, mention @dosu.
Self Checks
Dify version
0.10.2
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
When uploading a file locally, a .docx file saved by WPS was selected. The frontend reports Unsupported file type.
Analysis of the error: In web/app/components/base/file-uploader/utils.ts, the getFileExtension method is entirely dependent on the third-party package mime for determination and cannot correctly handle files where fileMimetype is application/wps-office.docx (files generated by WPS):
It is suggested to adjust the method so that it does not solely rely on mime. If mime cannot handle it, directly return the suffix:
✔️ Expected Behavior
Capable of supporting files of WPS and other office software types.
❌ Actual Behavior
Actually not supported