lobehub / lobe-chat

🤯 Lobe Chat - an open-source, modern-design AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Azure / DeepSeek), Knowledge Base (file upload / knowledge management / RAG ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT/ Claude application.
https://chat-preview.lobehub.com
Other
44.34k stars 9.94k forks source link

[Bug] Unable to Upload PDF in Chat Using "Upload File" Feature #3929

Closed samkurd closed 3 weeks ago

samkurd commented 1 month ago

📦 Environment

Vercel

📌 Version

v1.16.11

💻 Operating System

Windows

🌐 Browser

Edge

🐛 Bug Description

When attempting to use the "Upload File" feature to upload a PDF file in the chat with assistants, an error occurs consistently. This issue is specific to the chat interface, as uploading PDFs in the "Files" section works normally and can be accessed in the "Knowledge Base" feature within the chat.

Screenshot of the error:

Request Failed Sorry, the server seems to be experiencing some difficulties and is temporarily unable to complete your request. Please try again later. Error detail: Invalid key length

Below is what I see in the console log:

https://mydomain.com/trpc/lambda/chunk.createParseFileTask?batch=1

📷 Recurrence Steps

  1. Install Lobe-chat using server database and Cloudflare R2 Storage
  2. Open a chat with an assistant
  3. Attempt to use the "Upload File" feature to upload a PDF file

🚦 Expected Behavior

The PDF file should upload normally and be available for use in the chat.

📝 Additional Information

I have attached two screenshot of the error. image image

lobehubbot commented 1 month ago

👀 @samkurd

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

dosubot[bot] commented 1 month ago

Hey there, @samkurd! I'm here to assist you with any bugs, questions, or contributions. Let's work together to solve this issue.

I found a similar closed issue: [Request] cannot upload files, except images, which was resolved by a pull request: ✨ feat: files and knowledge base on August 21, 2024 [1].

The issue you're experiencing with uploading a PDF in the chat using the "Upload File" feature in version v1.16.11 on Windows with Edge could be related to the FILE_UPLOAD_BLACKLIST filter applied in the uploadChatFiles function. However, the FILE_UPLOAD_BLACKLIST only includes ['.DS_Store'] and does not blacklist PDFs [2].

The "Invalid key length" error might be due to an issue during the file upload process. The uploadChatFiles function has specific error handling mechanisms that catch errors and provide detailed notifications. Here is the relevant code snippet:

try {
  fileResult = await get().uploadWithProgress({
    file,
    onStatusUpdate: dispatchChatUploadFileList,
  });
} catch (error) {
  // skip `UNAUTHORIZED` error
  if ((error as any)?.message !== 'UNAUTHORIZED')
    notification.error({
      description:
        // it may be a network error or the cors error
        error === UPLOAD_NETWORK_ERROR
          ? t('upload.networkError', { ns: 'error' })
          : // or the error from the server
            typeof error === 'string'
            ? error
            : t('upload.unknownError', { ns: 'error', reason: (error as Error).message }),
      message: t('upload.uploadFailed', { ns: 'error' }),
    });

  dispatchChatUploadFileList({ id: file.name, type: 'removeFile' });
}

This mechanism can help provide more insight into the "Invalid key length" error by displaying the error message in the notification [3].

To further investigate, you might want to check the server logs for more details on the "Invalid key length" error and ensure that the server configuration is correct for handling PDF uploads.

To continue talking to Dosu, mention @dosu.

arvinxx commented 1 month ago

check your server log please.

samkurd commented 1 month ago

this is the server log for the error, please let me know if this is enough.

97013-02472d5cb275a608.js:1

    POST https://lobe.mydomain.com/trpc/lambda/chunk.createParseFileTask?batch=1 500 (Internal Server Error)

fetch @ 97013-02472d5cb275a608.js:1 S @ 73920-aba4224cf1d54a1e.js:1 await in S j @ 73920-aba4224cf1d54a1e.js:1 v @ 73920-aba4224cf1d54a1e.js:1 fetch @ 73920-aba4224cf1d54a1e.js:1 o @ 73920-aba4224cf1d54a1e.js:1 setTimeout load @ 73920-aba4224cf1d54a1e.js:1 (anonymous) @ 73920-aba4224cf1d54a1e.js:1 subscribe @ 73920-aba4224cf1d54a1e.js:1 (anonymous) @ 73920-aba4224cf1d54a1e.js:1 subscribe @ 73920-aba4224cf1d54a1e.js:1 (anonymous) @ 73920-aba4224cf1d54a1e.js:1 subscribe @ 73920-aba4224cf1d54a1e.js:1 (anonymous) @ 73920-aba4224cf1d54a1e.js:1 (anonymous) @ 73920-aba4224cf1d54a1e.js:1 requestAsPromise @ 73920-aba4224cf1d54a1e.js:1 mutation @ 73920-aba4224cf1d54a1e.js:1 (anonymous) @ 73920-aba4224cf1d54a1e.js:1 apply @ 73920-aba4224cf1d54a1e.js:1 createParseFileTask @ 18264-326e6854cdf5a209.js:1 (anonymous) @ 18264-326e6854cdf5a209.js:1 startAsyncTask @ 18264-326e6854cdf5a209.js:1 (anonymous) @ 18264-326e6854cdf5a209.js:1 await in (anonymous) uploadChatFiles @ 18264-326e6854cdf5a209.js:1 await in uploadChatFiles beforeUpload @ default-efa24d9095913747.js:1 i @ 9106-0ac884af3a487b36.js:1 (anonymous) @ 9106-0ac884af3a487b36.js:1 beforeUpload @ 9106-0ac884af3a487b36.js:1 (anonymous) @ 9106-0ac884af3a487b36.js:1 p @ 97322-ee173d23dcff0905.js:1 a.value @ 97322-ee173d23dcff0905.js:1 (anonymous) @ 97322-ee173d23dcff0905.js:1 r @ 97322-ee173d23dcff0905.js:1 c @ 97322-ee173d23dcff0905.js:1 (anonymous) @ 97322-ee173d23dcff0905.js:1 (anonymous) @ 97322-ee173d23dcff0905.js:1 (anonymous) @ 9106-0ac884af3a487b36.js:1 (anonymous) @ 9106-0ac884af3a487b36.js:1 (anonymous) @ 9106-0ac884af3a487b36.js:1 (anonymous) @ 9106-0ac884af3a487b36.js:1 a_ @ fd9d1056-aea7120c0817ed17.js:1 aR @ fd9d1056-aea7120c0817ed17.js:1 (anonymous) @ fd9d1056-aea7120c0817ed17.js:1 sF @ fd9d1056-aea7120c0817ed17.js:1 sM @ fd9d1056-aea7120c0817ed17.js:1 (anonymous) @ fd9d1056-aea7120c0817ed17.js:1 o4 @ fd9d1056-aea7120c0817ed17.js:1 iV @ fd9d1056-aea7120c0817ed17.js:1 sU @ fd9d1056-aea7120c0817ed17.js:1 uR @ fd9d1056-aea7120c0817ed17.js:1 uM @ fd9d1056-aea7120c0817ed17.js:1

arvinxx commented 1 month ago

It seems your issue is the file can be fetched. Check your s3 config

samkurd commented 1 month ago

Thanks @arvinxx , what do you think has been misconfigured? I'm using Cloudflare. and one more thing, when I upload the files using the "Files" Section there is no error or issues while uploading PDFs. image

jzworkmagic commented 1 month ago

Hi @samkurd Have you solved this issue? If you have solved it, could you tell me how to solve it? Thanks

amanbolat commented 1 month ago

Hello, I have encountered the same issue as @samkurd. If I try to upload a PDF file in the chat then it fails with error. Though it can be uploaded from files menu.

arvinxx commented 3 weeks ago

if the error is Invalid key length, you must set a wrong KEY_VAULTS_SECRET , please check the document: https://lobehub.com/docs/self-hosting/server-database#key-vaults-secret

lobehubbot commented 3 weeks ago

✅ @samkurd

This issue is closed, If you have any questions, you can comment and reply.\ 此问题已经关闭。如果您有任何问题,可以留言并回复。