Repository navigation
fix(rn): uploadFile sends the real file name instead of hardcoded 'file' - #19507
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Walkthrough该变更修正 RN ChangesRN uploadFile 文件名支持
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The filename override, URI-path basename fallback, and legacy fallback behavior are covered without an actionable current risk. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 小兔背着表单包,沿着 Comment |
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:
|
ccc5cc5 to
b0f096b
Compare
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
b0f096b to
0e3202a
Compare
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。