feat(ecommerce): use FormData binary upload instead of base64 dataUrl

- Add uploadAssetBinary method to aiGenerationClient (FormData + busboy)
- Replace base64 dataUrl upload in uploadProductImages with direct blob upload
  via /oss/upload-binary multipart endpoint
- This eliminates the DATA_URL_PATTERN regex parsing bug that produced
  44-byte corrupt files on OSS, causing DashScope "image format illegal" errors

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 16:03:50 +08:00
parent 160552b45e
commit 44c748b0dc
2 changed files with 20 additions and 9 deletions
+4 -9
View File
@@ -1326,15 +1326,10 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
for (const item of productImages) {
try {
const resp = await fetch(item.src);
const blob = await resp.blob();
const mimeType = SUPPORTED_IMAGE_TYPES.has(blob.type) ? blob.type : "image/png";
const dataUrl = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(String(reader.result));
reader.onerror = () => reject(reader.error);
reader.readAsDataURL(blob);
});
const { url } = await aiGenerationClient.uploadAsset({ dataUrl, name: item.name, mimeType });
const rawBlob = await resp.blob();
const mimeType = SUPPORTED_IMAGE_TYPES.has(rawBlob.type) ? rawBlob.type : "image/png";
const blob = rawBlob.type === mimeType ? rawBlob : new Blob([rawBlob], { type: mimeType });
const { url } = await aiGenerationClient.uploadAssetBinary(blob, { name: item.name, mimeType, scope: "ecommerce-product" });
urls.push(url);
} catch {
// skip images that fail to upload