Skip to content

fix(onedrive): direct upload small file error#279

Closed
WoLeo-Z wants to merge 1 commit intoOpenListTeam:mainfrom
WoLeo-Z:fix/pr-249
Closed

fix(onedrive): direct upload small file error#279
WoLeo-Z wants to merge 1 commit intoOpenListTeam:mainfrom
WoLeo-Z:fix/pr-249

Conversation

@WoLeo-Z
Copy link
Copy Markdown

@WoLeo-Z WoLeo-Z commented Nov 17, 2025

OpenListTeam/OpenList#1668

Description / 描述

  • Simply remove the file.size > chunkSize check in the Frontend.

Motivation and Context / 背景

Relates to #249

When uploading files (size <= ChunkSize), server side uses upBig logic (for chunked upload) to request for the upload url, therefore the PUT request needs a header Content-Range.

But in frontend uploadSingle don't specify this header. Causing Upload failed with status 400.

{"error":{"code":"invalidRequest","message":"The Content-Range header is missing or malformed."}}

How Has This Been Tested? / 测试

0 < smallFileLimit (e.g. 4mb) < default ChunkSize (e.g. 5mb)

So there are 3 situations:

  • 3.5mb: Client receives ChunkSize = 0 and uses uploadSingle (1 PUT request)
  • 4.5mb: Client receives ChunkSize > 0 and uses uploadChunk but ChunkCount = 1 (1 PUT request)
  • 5.5mb: Client receives ChunkSize > 0 and uses uploadChunk but ChunkCount > 1 (multiple PUT requests)
fallocate -l 3.5M 3.5M.bin
fallocate -l 4.5M 4.5M.bin
fallocate -l 5.5M 5.5M.bin

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it’s needed).
    我已相应更新了相关仓库(若适用)。

@WoLeo-Z
Copy link
Copy Markdown
Author

WoLeo-Z commented Nov 18, 2025

Removing the file.size > chunkSize check may causing other direct upload functions broken. Review before merging.

(IMO if the file don't need chunked upload, chunkSize should be set 0.)

@WoLeo-Z
Copy link
Copy Markdown
Author

WoLeo-Z commented Dec 3, 2025

@KirCute PTAL

@KirCute
Copy link
Copy Markdown
Member

KirCute commented Dec 3, 2025

I'm not sure about OneDrive's upload logic. Perhaps you could consider contact @Y-ASLant?

Y-ASLant added a commit to Y-ASLant/OpenList-Frontend that referenced this pull request Dec 3, 2025
- 修复4-5MB文件直连上传400错误(移除file.size判断,确保Content-Range头设置)
- 添加上传文件大小显示(右对齐灰色文本)
- 实现上传速度实时计算(每500ms更新,使用闭包优化)
- 使用createSpeedCalculator函数复用速度计算逻辑,减少代码重复

修复问题: OpenListTeam#279
@Y-ASLant
Copy link
Copy Markdown
Contributor

Y-ASLant commented Dec 3, 2025

我不太确定OneDrive的上传逻辑。也许你可以考虑联系?

微软官方文档

微软官方规定

OneDrive 提供两种上传方式:

1. 简单上传 (Simple Upload)

  • 适用: 文件 ≤ 4MB
  • API: PUT /drive/items/{parent-id}:/{filename}:/content
  • 特点: 一次性上传,无需 Content-Range
PUT https://graph.microsoft.com/v1.0/me/drive/root:/file.txt:/content
Content-Type: application/octet-stream

[文件数据]

2. 会话上传 (Upload Session)

  • 适用: 文件 > 4MB
  • API: POST .../createUploadSessionPUT uploadUrl
  • 强制要求: 所有请求必须带 Content-Range 头(即使只有 1 块)
# 创建会话
POST https://graph.microsoft.com/v1.0/me/drive/root:/file.txt:/createUploadSession

# 上传分块(必须有 Content-Range)
PUT {uploadUrl}
Content-Range: bytes 0-5242879/10485760

[分块数据]

jyxjjj pushed a commit that referenced this pull request Dec 4, 2025
 fix:OneDrive直连上传并优化界面显示

- 修复4-5MB文件直连上传400错误(移除file.size判断,确保Content-Range头设置)
- 添加上传文件大小显示(右对齐灰色文本)
- 实现上传速度实时计算(每500ms更新,使用闭包优化)
- 使用createSpeedCalculator函数复用速度计算逻辑,减少代码重复

修复问题: #279
@WoLeo-Z
Copy link
Copy Markdown
Author

WoLeo-Z commented Dec 4, 2025

谢谢 #300 的贡献,测试了一下没有问题,close this pr

@WoLeo-Z WoLeo-Z closed this Dec 4, 2025
fsca8 pushed a commit to fsca8/OpenList-Frontend that referenced this pull request Feb 20, 2026
 fix:OneDrive直连上传并优化界面显示

- 修复4-5MB文件直连上传400错误(移除file.size判断,确保Content-Range头设置)
- 添加上传文件大小显示(右对齐灰色文本)
- 实现上传速度实时计算(每500ms更新,使用闭包优化)
- 使用createSpeedCalculator函数复用速度计算逻辑,减少代码重复

修复问题: OpenListTeam#279
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants