{{ message }}
Repository navigation
fix(rn): uploadFile sends the real file name instead of hardcoded 'file' - #19507
Merged
Single-Dancer merged 1 commit intoSep 29, 2026
Merged
Conversation
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19507 +/- ##
==========================================
- Coverage 54.66% 54.39% -0.27%
==========================================
Files 465 466 +1
Lines 25392 25551 +159
Branches 6364 6361 -3
==========================================
+ Hits 13880 13898 +18
- Misses 9636 9667 +31
- Partials 1876 1986 +110
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Single-Dancer
force-pushed
the
fix/rn-uploadfile-filename-19505
branch
from
September 29, 2026 03:32
ccc5cc5 to
b0f096b
Compare
Single-Dancer
approved these changes
Sep 29, 2026
On React Native, createFormData hardcoded the multipart file object's name to 'file', so backends could not read the original file name or extension (e.g. to distinguish image types). The H5 implementation already forwards a meaningful name (option fileName, blob name, or a generated fallback). RN now resolves the name as: explicit fileName option, then the filePath basename, then the historical 'file' fallback. The public Taro.uploadFile.Option type already exposes fileName; its @supported tag is updated to include rn. Adds regression tests covering the basename derivation, the explicit fileName override, and the 'file' fallback. Fixes NervJS#19505
Single-Dancer
force-pushed
the
fix/rn-uploadfile-filename-19505
branch
from
September 29, 2026 06:29
b0f096b to
0e3202a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What this PR does / 这个 PR 做了什么
On React Native,
uploadFilebuilds the multipart file object with a hardcodedname: 'file', so the server always receives the file namefileand cannot read the original name or extension (e.g. to distinguish image types), as reported in #19505.RN 端
uploadFile组装 multipart 文件对象时把name写死为'file',后端拿不到真实文件名/后缀(#19505)。The H5 implementation already sends a meaningful file name (
form.append(name, fileObj, fileName || \file-${Date.now()}`)), and the publicTaro.uploadFile.Optiontype already exposesfileName`. RN is the outlier.How / 修改方式
packages/taro-rn/src/lib/file.ts—createFormDatanow resolves the file name as:fileNameoption, thenfilePathbasename (e.g.xxxx.jpg), then'file'fallback when neither exists.packages/taro/types/api/network/upload.d.ts—fileName的@supported标记从h5更新为h5, rn(该选项类型本来就存在,仅文档标记未覆盖 RN)。Verification / 验证
nameis always'file'); the fallback case passes on both old and new code, pinning backward compatibility.packages/taro-rnfull Jest suite — 14 suites / 36 passed / 1 skipped, including the new__tests__/uploadFile.test.ts(basename derivation, explicitfileNameoverride,'file'fallback).tsc --noEmitonpackages/taro-rn: zero errors in changed files (the single remaining error is the pre-existing@tarojs/runtime-rnworkspace build-order issue in untouchedsrc/api/index.ts, identical before and after).git diff --checkclean.Note: the package's own
testMatchglob does not match on Windows (mixed separators), so tests were run withnpx jest --testMatch '**/__tests__/**/*.test.ts'— same suites, no repo config changes.Fixes #19505
Summary by CodeRabbit
fileName。application/octet-stream。