Met error "上传失败 可能是文件体积过大", but fixed with deepseek

Open
#280 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
nginx, typescript

Research direction

Start by reviewing the uploadFile entry point shown in the issue and locate the repository's default nginx configuration, whose file path is not specified here. Reproduce an upload through the reverse proxy and verify the proposed configuration against the observed error; done means the default setup handles supported uploads without the misleading failure.

Written by the indexing model from the issue text.

Description

Using default nginx config for reverse proxy, but meeting errors "上传失败 可能是文件体积过大", have assured that all tailchat concerned containers have been removed and started more than once, error still exists.

After check the source code, found this

export async function uploadFile(
  file: File,
  options: UploadFileOptions = {}
): Promise<UploadFileResult> {
  const form = new FormData();
  form.append('file', file);
  form.append('usage', options.usage ?? 'unknown');

  const uploadFileLimit = getGlobalConfig().uploadFileLimit;
  if (file.size > uploadFileLimit) {
    // 文件过大
    showErrorToasts(
      `${t('上传失败, 支持的文件最大大小为:')} ${filesize(uploadFileLimit, {
        base: 2,
      })}`
    );
    throw new Error('File Too Large');
  }

  try {
    const { data } = await request.post('/upload', form, {
      onUploadProgress(progressEvent) {
        if (progressEvent.lengthComputable) {
          if (typeof options.onProgress === 'function') {
            options.onProgress(
              progressEvent.loaded / progressEvent.total,
              progressEvent
            );
          }
        }
      },
    });

    return data;
  } catch (e) {
    showToasts(`${t('上传失败')}: ${t('可能是文件体积过大')}`, 'error');
    console.error(`${t('上传失败')}: ${_get(e, 'message')}`);
    throw e;
  }
}

So I guess this error was not raised by tailchat but nginx.
Whatever, this is a better config for nginx, if here were any mistake, that would all deepseek's fault😁, but I have tested in nginx 1.26.2, here is nothing wrong with it. I suggest @moonrailgun updating nginx default config
Enjoy.

gzip on;
gzip_types
    text/css
    text/javascript
    application/javascript
    application/json;

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    listen 80;
    listen [::]:80;
    server_name tailchat.domain.com;
    return 301 https://$host$request_uri;  
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name tailchat.domain.com;


    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_ecdh_curve secp384r1;  
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;

    ssl_certificate /etc/cert/tailchat.domain.com;
    ssl_certificate_key /etc/cert/tailchat.domain.com;

    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;


    proxy_http_version 1.1;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_max_temp_file_size 1024m;
    client_max_body_size 1024M;


    location ~ ^/socket\.io(/|$) {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade; 
        proxy_pass http://127.0.0.1:11000;
        proxy_read_timeout 86400;
    }


    location / {
        proxy_pass http://127.0.0.1:11000;
    }


    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;


    access_log /var/log/nginx/tailchat-access.log combined buffer=64k flush=5m;
    error_log /var/log/nginx/tailchat-error.log warn;
}
Dominant language
TypeScript
Stars
3.6k
Forks
398
Avg merge
1h 14m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from msgbyte/tailchat

All issues in msgbyte/tailchat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.