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

Bugfix/Address file name with special chars #3496

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ const uploadFilesToAssistantVectorStore = async (req: Request, res: Response, ne

if (Array.isArray(files)) {
for (const file of files) {
// Address file name with special characters: https://github.com/expressjs/multer/issues/1104
file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8')
uploadFiles.push({
filePath: file.path,
fileName: file.originalname
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/controllers/openai-assistants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const uploadAssistantFiles = async (req: Request, res: Response, next: NextFunct

if (Array.isArray(files)) {
for (const file of files) {
// Address file name with special characters: https://github.com/expressjs/multer/issues/1104
file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8')
uploadFiles.push({
filePath: file.path,
fileName: file.originalname
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/utils/buildChatflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
const fileNames: string[] = []
for (const file of files) {
const fileBuffer = fs.readFileSync(file.path)

// Address file name with special characters: https://github.com/expressjs/multer/issues/1104
file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8')
const storagePath = await addArrayFilesToStorage(file.mimetype, fileBuffer, file.originalname, fileNames, chatflowid)

const fileInputFieldFromMimeType = mapMimeTypeToInputField(file.mimetype)
Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/utils/createAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const createFileAttachment = async (req: Request) => {
for (const file of files) {
const fileBuffer = fs.readFileSync(file.path)
const fileNames: string[] = []

// Address file name with special characters: https://github.com/expressjs/multer/issues/1104
file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8')

const storagePath = await addArrayFilesToStorage(file.mimetype, fileBuffer, file.originalname, fileNames, chatflowid, chatId)

const fileInputFieldFromMimeType = mapMimeTypeToInputField(file.mimetype)
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/utils/upsertVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
for (const file of files) {
const fileNames: string[] = []
const fileBuffer = fs.readFileSync(file.path)

// Address file name with special characters: https://github.com/expressjs/multer/issues/1104
file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8')
const storagePath = await addArrayFilesToStorage(file.mimetype, fileBuffer, file.originalname, fileNames, chatflowid)

const fileInputFieldFromMimeType = mapMimeTypeToInputField(file.mimetype)
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/views/chatmessage/ChatMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview

if (fullFileUpload) {
const filesWithFullUploadType = uploadedFiles.filter((file) => file.type === 'file:full')

if (filesWithFullUploadType.length > 0) {
const formData = new FormData()
for (const file of filesWithFullUploadType) {
Expand All @@ -712,12 +711,14 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview

const response = await attachmentsApi.createAttachment(chatflowid, chatId, formData)
const data = response.data

for (const extractedFileData of data) {
const content = extractedFileData.content
const fileName = extractedFileData.name

// find matching name in previews and replace data with content
const uploadIndex = uploads.findIndex((upload) => upload.name === fileName)

if (uploadIndex !== -1) {
uploads[uploadIndex] = {
...uploads[uploadIndex],
Expand Down
Loading