[PR #31204] fix: Upload csv file to run batch support Simplified Chinese encoding. #33134

Open
opened 2026-02-21 20:52:43 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/31204

State: open
Merged: No


fix: Upload csv file to run batch support Simplified Chinese encoding. (#31190)

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.
    Fixes [PR #25746] optimize lindorm vdb and configuration (#31190)

Summary

Upload csv file to run batch support Simplified Chinese encoding

Screenshots

After

  onUploadAccepted={async (results: any, file: File) => {
    if (!file) {
      onParsed(results.data)
      setZoneHover(false)
      return
    }

    const buffer = await file.arrayBuffer()
    // jschardet requires a buffer or a string of bytes
    const uint8Array = new Uint8Array(buffer)
    // jschardet.detect accepts string | Buffer, convert to string for browser compatibility
    const detected = jschardet.detect(uint8Array.reduce((data, byte) => data + String.fromCharCode(byte), ''))

    let encoding = detected.encoding
    // jschardet can sometimes misidentify GBK as 'windows-1252'.
    // This is a heuristic to handle such cases.
    if (encoding === 'windows-1252' || encoding === 'ISO-8859-2') {
      encoding = 'GBK'
    }

    // Use UTF-8 as a fallback for unsupported or uncertain encodings.
    const supportedEncodings = ['UTF-8', 'GBK', 'GB18030', 'BIG5']
    if (!encoding || !supportedEncodings.includes(encoding.toUpperCase())) {
      encoding = 'UTF-8'
    }

    const text = new TextDecoder(encoding, { fatal: false }).decode(buffer)

    parse(text, {
      worker: true,
      complete: (results: ParseResult<string[]>) => {
        onParsed(results.data)
        setZoneHover(false)
      },
    })
  }}

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/31204 **State:** open **Merged:** No --- fix: Upload csv file to run batch support Simplified Chinese encoding. (#31190) > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. Fixes #31190 ## Summary Upload csv file to run batch support Simplified Chinese encoding ## Screenshots After onUploadAccepted={async (results: any, file: File) => { if (!file) { onParsed(results.data) setZoneHover(false) return } const buffer = await file.arrayBuffer() // jschardet requires a buffer or a string of bytes const uint8Array = new Uint8Array(buffer) // jschardet.detect accepts string | Buffer, convert to string for browser compatibility const detected = jschardet.detect(uint8Array.reduce((data, byte) => data + String.fromCharCode(byte), '')) let encoding = detected.encoding // jschardet can sometimes misidentify GBK as 'windows-1252'. // This is a heuristic to handle such cases. if (encoding === 'windows-1252' || encoding === 'ISO-8859-2') { encoding = 'GBK' } // Use UTF-8 as a fallback for unsupported or uncertain encodings. const supportedEncodings = ['UTF-8', 'GBK', 'GB18030', 'BIG5'] if (!encoding || !supportedEncodings.includes(encoding.toUpperCase())) { encoding = 'UTF-8' } const text = new TextDecoder(encoding, { fatal: false }).decode(buffer) parse(text, { worker: true, complete: (results: ParseResult<string[]>) => { onParsed(results.data) setZoneHover(false) }, }) }} ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33134