Skip to content

Commit

Permalink
docs(uploader): update (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu authored May 17, 2024
1 parent 46db831 commit beb730e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/packages/uploader/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { Uploader } from '@nutui/nutui-react';
> When using the Uploader component to upload files, you may encounter the problem of garbled Chinese characters in the response file information. This usually happens when the client and server are inconsistent in how they handle the encoding of the file. To avoid this problem, it is recommended to ensure that the encoding format of the file read by the server is consistent with that of the client.
```javascript
import React from 'react'
import { Uploader } from '@nutui/nutui-react'
// Server Demo
app.post('/upload', upload.single('file'), (req, res) => {
const fileEncoding = req.headers['x-file-encoding'] || 'UTF-8';
Expand Down
4 changes: 3 additions & 1 deletion src/packages/uploader/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ import { Uploader } from '@nutui/nutui-react';
> 在使用Uploader组件上传文件时,可能会遇到响应文件信息中文乱码的问题。这通常发生在客户端与服务器端在处理文件编码时不一致的情况下。为了避免这种问题,建议确保服务器端读取文件的编码格式与客户端保持一致。
```javascript
import React from 'react'
import { Uploader } from '@nutui/nutui-react'
// Server Demo
app.post('/upload', upload.single('file'), (req, res) => {
const fileEncoding = req.headers['x-file-encoding'] || 'UTF-8';
const fileContent = iconv.decode(Buffer.from(JSON.stringify(req.file), 'binary'), fileEncoding);
res.json({ success: true, message: 'File uploaded successfully', data: JSON.parse(fileContent) });
});

// Client Demo
<Uploader url={uploadUrl} headers={{'x-file-encoding': 'UTF-8'}} />

```

### 基础用法
Expand Down
2 changes: 2 additions & 0 deletions src/packages/uploader/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { Uploader } from '@nutui/nutui-react-taro';
> 在使用Uploader组件上传文件时,可能会遇到响应文件信息中文乱码的问题。这通常发生在客户端与服务器端在处理文件编码时不一致的情况下。为了避免这种问题,建议确保服务器端读取文件的编码格式与客户端保持一致。
```javascript
import React from 'react'
import { Uploader } from '@nutui/nutui-react'
// Server Demo
app.post('/upload', upload.single('file'), (req, res) => {
const fileEncoding = req.headers['x-file-encoding'] || 'UTF-8';
Expand Down
2 changes: 2 additions & 0 deletions src/packages/uploader/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { Uploader } from '@nutui/nutui-react';
> 在使用Uploader組件上傳文件時,可能會遇到響應文件信息中文亂碼的問題。這通常發生在客戶端與服務器端在處理文件編碼時不一致的情況下。為了避免這種問題,建議確保服務器端讀取文件的編碼格式與客戶端保持一致。
```javascript
import React from 'react'
import { Uploader } from '@nutui/nutui-react'
// Server Demo
app.post('/upload', upload.single('file'), (req, res) => {
const fileEncoding = req.headers['x-file-encoding'] || 'UTF-8';
Expand Down

0 comments on commit beb730e

Please sign in to comment.