feat(upload): add chunked upload support for form mode. 添加分片逻辑。#356
Open
LusiyAvA wants to merge 2 commits intoOpenListTeam:mainfrom
Open
feat(upload): add chunked upload support for form mode. 添加分片逻辑。#356LusiyAvA wants to merge 2 commits intoOpenListTeam:mainfrom
LusiyAvA wants to merge 2 commits intoOpenListTeam:mainfrom
Conversation
Open
9 tasks
Fill in the help English field in /src/lang/en/settings.json.
KirCute
requested changes
Jan 7, 2026
| } | ||
| } | ||
|
|
||
| export const FormUpload: Upload = async ( |
Member
There was a problem hiding this comment.
不应覆盖原有form上传逻辑,分片上传和原form应作为两种上传方式供用户选择
| } | ||
|
|
||
| // Keep old signature for compatibility if needed, but we essentially replace it | ||
| export const calculateHash = async (file: File) => { |
Comment on lines
+22
to
+34
| async function generateUploadId(path: string, file: File): Promise<string> { | ||
| const sample = file.slice(0, Math.min(1024 * 1024, file.size)) | ||
| const buffer = await sample.arrayBuffer() | ||
| const hashBuffer = await crypto.subtle.digest("SHA-256", buffer) | ||
| const hashHex = Array.from(new Uint8Array(hashBuffer)) | ||
| .slice(0, 8) | ||
| .map((b) => b.toString(16).padStart(2, "0")) | ||
| .join("") | ||
| // Use encodeURIComponent to handle Unicode characters before btoa | ||
| const rawId = `${path}|${file.size}|${hashHex}` | ||
| const encodedId = btoa(encodeURIComponent(rawId)) | ||
| return encodedId.replace(/[+/=]/g, "_") | ||
| } |
Member
There was a problem hiding this comment.
二选一:
- 应在服务端生成upload_id
- 服务端应校验upload_id与首个分片的哈希值是否一致,同时在首个分片上传成功前拒绝其它分片
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.
Description / 描述
This PR implements the frontend logic for chunked file uploads in form mode, corresponding to the backend changes.
此 PR 实现了 Form 模式下分片上传的前端逻辑,以配合后端的变更。
Key changes include:
主要更改包括:
文件切片:实现了上传前根据后台配置对文件进行切片的逻辑。
crc-32calculation for each chunk to ensure data integrity during transmission.完整性校验:为每个分片添加了
crc-32计算,以确保传输过程中的数据完整性。上传循环:更新了上传组件以处理分片的顺序上传和错误重试。
Motivation and Context / 背景
Standard form uploads are prone to failure with large files or unstable network conditions. Introducing chunked uploads improves reliability and user experience.
普通的表单上传在处理大文件或网络不稳定时容易失败。引入分片上传可以显著提高可靠性和用户体验。
Relates to OpenListTeam/OpenList#1928
How Has This Been Tested? / 测试
手动测试了 Form 模式下上传大于 500MB 的大文件。
crc-32is correctly calculating checksums for chunks.验证了
crc-32能正确计算分片的校验和。验证了配合后端 (PR #1928) 能成功合并文件。
Checklist / 检查清单
我已阅读 CONTRIBUTING 文档。
go fmtor prettier.我已使用
go fmt或 prettier 格式化提交的代码。(Maintainers please add
featandfrontendlabels / 请维护者添加feat和frontend标签)我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
我已相应更新了相关仓库(若适用)。