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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user