Multipart Upload from HarmonyOS ArkTS to Huawei Cloud OBS

举报
yd_285790621 发表于 2026/11/18 09:19:02 2026/11/18
【摘要】 What I did todayToday I worked through a real upload problem in the HarmonyOS practice case “Build a personal cloud photo album app with OBS” from the Harmony Development Practice Center. I opened...

What I did today

Today I worked through a real upload problem in the HarmonyOS practice case “Build a personal cloud photo album app with OBS” from the Harmony Development Practice Center. I opened the case, read how it uploads photos to Huawei Cloud OBS, and then used the free trial of AI DevSpace to work out how to extend that flow to large video files. This post records the steps and the result.

What the case already does

  • Small files such as photos are uploaded with a single PUT request.
  • Requests use HMAC-SHA1 header signature authentication: the client builds a canonical string from the HTTP method, headers and resource path, signs it with the Secret Key, and sends Authorization: OBS <AccessKey>:<Signature>. The signature is valid for 15 minutes.
  • Uploads carry a Base64 Content-MD5 so OBS can verify integrity, and the app derives the file MD5 in JavaScript before sending.

The problem

A single PUT has to be re-sent from the beginning if the connection drops, and a video of 100 MiB or more makes that likely on a mobile network. I needed a resumable upload path instead of a bigger single request.

The multipart upload flow

The design I worked out in AI DevSpace has six steps:

  1. InitiateMultipartUpload — POST ?uploads returns an UploadId. Persist it (for example in the app local storage) so the upload can resume after the app restarts.
  2. Split the file into parts — every part must be at least 5 MiB except the last one, and part numbers run from 1 to 10000 in ascending order. Example: a 120 MiB video split into 5 MiB parts gives 24 parts.
  3. UploadPart — PUT each part with ?partNumber=<n>&uploadId=<id> and include the part MD5 in Base64. OBS returns an ETag for each part; record the part number and its ETag.
  4. CompleteMultipartUpload — POST ?uploadId=<id> with an XML body listing every part number and ETag in order.
  5. Verify — GET or HEAD the object afterwards. Important: the resulting ETag is a composite MD5 with a -<part count> suffix. It is not the MD5 of the whole file, so do not compare it against the file MD5.
  6. Clean up on failure — call AbortMultipartUpload for a failed upload so orphaned parts do not linger. OBS lifecycle rules can also expire incomplete multipart uploads automatically.

Error-handling rules I took away

  • Retry only the failed part, with backoff and jitter. Never restart the whole file.
  • Persist the UploadId and the list of completed parts before uploading, so the app can resume after a crash.
  • Validate the CompleteMultipartUpload XML against its schema before sending. One malformed part entry fails the whole completion.
  • Keep credentials out of the client. The case signs requests inside the app for learning purposes, but a production app should move signing to a backend service.

Result

I now have a concrete, implementable design for large-file video upload in the photo album case: part sizing, the ETag check, and the retry rules are all settled. The next step is to wire this into the case video upload path and test with a 120 MiB file on the API 24 emulator, including a resume-after-kill test.

Note: these are practice notes from today’s session, not a production deployment. The part-size minimum (5 MiB), the 10000-part limit and the composite ETag rule are OBS rules I confirmed during the session.

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0)

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。