dcloudio / dcloudio/uni-app

[Bug] uni.uploadFile 的 files 参数在 App 端和 H5 端行为不一致,相同 name 时 App 只能上传一个文件

Open
#5,893 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
41.6k
Forks
3.7k
Avg merge
7h 6m
Merged PRs (30d)
6

Description

### 问题分类

uni-app

### 问题描述

使用 `uni.uploadFile` 的 `files` 参数批量上传多个文件时,如果所有文件的 `name` 相同:
- **H5 端**:能正常上传所有文件 ✅
- **App 端**:只能上传第一个文件,其余文件丢失 ❌

这导致同一套代码在不同平台表现不一致,违背了 uni-app "一套代码,多端运行" 的核心理念。

### 复现步骤

```javascript
const files = [
{ name: 'images', uri: '/path/to/file1.jpg' },
{ name: 'images', uri: '/path/to/file2.jpg' },
{ name: 'images', uri: '/path/to/file3.jpg' },
]

uni.uploadFile({
url: 'https://example.com/upload',
files: files,
success: (res) => {
console.log(res)
}
})
```

### 实际结果

| 平台 | 结果 |
|------|------|
| H5 | 服务端收到 3 个文件 ✅ |
| App | 服务端只收到 1 个文件 ❌ |

### 期望结果

App 端和 H5 端行为一致,都能正常上传所有文件。

### 附加信息

### 环境信息

- **HBuilderX 版本**:4.07
- **uni-app 版本**:3.0.0
- **测试平台**:Android App、H5
- **手机系统版本**:Android 12

### 相关文档

[uni.uploadFile 官方文档](https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile) 中提到:

> 如果 `name` 不填或填的值相同,可能导致服务端读取文件时只能读取到一个文件。

但这个提示不够明显,且没有说明 H5 和 App 行为不一致的问题。建议:
1. 框架层面自动处理
2. 或在文档中更醒目地标注平台差异

另外:

H5 端浏览器帮你处理了
App 端框架没帮你处理
导致同一套代码在不同平台行为不一致
这恰恰违背了 uni-app 的核心点:"一套代码,多端运行"

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.