HarmonyOS OBS Album: a 403 Signature Checklist from AI DevSpace
Saturday, 14 November 2026. I spent the morning on the HarmonyOS practice case “用OBS打造个人云相册app” (building a personal cloud photo album app with OBS), and I used the one error that case is most likely to produce as a real test for AI DevSpace. This note is what actually happened, in the order it happened, including the parts where the AI had to work around its own failures.
The case itself
The case is listed as advanced, about 120 minutes, and sits on the learning path Storage → Cloud Data Migration (CDM) → Object Storage (OBS). The code lives at harmony-practice-center/HarmonyOS-APP-OBSCloudAlbum on GitCode.
The idea is simple enough: you create a private OBS bucket, take an AK/SK pair, and upload photos from a HarmonyOS app file by file using a Header signature — HMAC-SHA1, with the request carrying Authorization: OBS <AccessKey>:<Signature>. A local file keeps the backup record, and the app can preview photos from the cloud afterwards. Nothing in the case is exotic, which is exactly why the signature step deserves attention: it is the one place where a single wrong character gives you nothing but a 403.
I read the case detail page and let it sit open well past the 30-second mark, then starred the repo. The star count moved from 1194 to 1195 — that part is confirmed on GitCode. The Grow Center had already credited the browse, so my points went 950 → 960.
The question I took to AI Shell
Inside AI DevSpace I opened AI Shell (trial edition, the free one — a 3-hour container, 02:59 left when I started) and asked, in Chinese:
我正在做鸿蒙 OBS 个人云相册案例:用 HMAC-SHA1 做 OBS Header 签名,Authorization 是 OBS AK:Signature,逐文件上传照片到私有桶。如果上传返回 403 SignatureDoesNotMatch,按什么顺序排查最省时间?请具体说规范化字符串里最容易错的几项,以及怎么用实际返回的响应定位问题。
I sent that at 10:41:58. Watching the session work was instructive in itself. Its first move was a web search for the OBS signature docs — that failed twice with HTTP 429, the keyless daily cap. It then went and fetched the official OBS API docs directly (support.huaweicloud.cn/api-obs/obs_04_0010.html and obs_04_0011.html), grepped them for StringToSign, and read the signature sections line by line. It also tried three guessed troubleshooting URLs under trouble-obs/ (obs_49_0003, obs_49_0002, obs_49_0001) — all three came back 404, and it said so rather than inventing what was on them. The final answer arrived at 10:45:41, about four minutes after the question.
The checklist it gave me, and the part that matters most
The core of the answer is one formula:
StringToSign = HTTP-Verb + "\n"
+ Content-MD5 + "\n"
+ Content-Type + "\n"
+ Date + "\n"
+ CanonicalizedHeaders
+ CanonicalizedResource
Signature = Base64(HMAC-SHA1(SK, StringToSign))
A 403 SignatureDoesNotMatch means the StringToSign you built locally is not the one OBS built on its side from the same request. The HMAC and Base64 lines are almost never the problem — the string you feed them is. That framing is the useful part; the rest is just working through the string in the order things usually break:
- Compare against the server’s StringToSign first. OBS returns its own StringToSign inside the 403 response body, in XML. Log your StringToSign too (replace the newlines with a visible
\nfirst, or the line breaks disappear in the log), then line the two up side by side. The first line that differs is your bug. The official sample code even carries this as a comment: print the StringToSign when you get a 403. - Content-Type, the most common mismatch. What you sign has to be byte-for-byte what the request actually sends.
image/jpegsigned againstimage/jpgsent, or an empty string signed while the framework quietly added a Content-Type header, both fail. HarmonyOS’s@ohos.net.httpHttpRequest can add Content-Type and Content-Length on its own when there is a body — set Content-Type explicitly and use the same value for signing and sending. - Date and x-obs-date. The date must be RFC 1123 GMT. If you send
x-obs-dateinstead ofDate, the Date line in StringToSign stays empty and the time goes into CanonicalizedHeaders. A clock off by more than 15 minutes is a different error,RequestTimeTooSkewed, but it is close enough to the same neighbourhood to be worth ruling out. - CanonicalizedHeaders. Names lowercase, values as-is, sorted by name, no space after the colon, each header ending with
\n— and no extra\nwhen there are nox-obs-headers at all. That last one is the kind of detail you only get wrong once. - CanonicalizedResource.
/<bucket>/<object>, with the object name encoded the same way in the signed string and in the actual request URL. Photo albums make this real: file names with Chinese characters or spaces, like2025年11月/IMG_001.jpg, andencodeURIComponent(which encodes/) versusencodeURI(which does not) will quietly disagree with each other. - The small items. Content-MD5 is an empty string when you do not set it, not
"null"; the verb is uppercasePUT, notput; and a temporary AK/SK pair needsx-obs-security-tokenin CanonicalizedHeaders, or the signature will never match no matter how careful the rest is.
Two HarmonyOS-specific traps from the answer are worth keeping together: don’t stamp a fresh new Date() when signing and let the framework stamp another one when sending — one shared time string for both, especially if you sign a batch of files ahead of time and upload them with a delay; and don’t let the HTTP layer add headers you didn’t sign.
A short note on the day’s scoreboard
Signing in this morning made it six days in a row, and the browse credit landed promptly (940 → 950 → 960). Two things had not landed when I checked at around 10:46: the +30 for the Star and the +30 for the DevSpace visit. The Star itself is visible on GitCode, so this looks like the platform’s credit sync lagging — the same thing happened with yesterday’s Star on the todo_list repo, which never appeared in the November 13 points detail at all. I’ll check the points detail again later rather than guess at it here.
One last observation from the session: AI Shell’s search being capped did not stop it, because it could still fetch the docs directly and say plainly when a page was missing. For this kind of debugging question, the tool’s most useful habit was showing its working — the failed searches, the fetched pages, the 404s — so I could tell which parts of the answer came from the documentation and which parts were the model’s own reasoning.
- 点赞
- 收藏
- 关注作者
评论(0)