Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import type { ImageUploadInitResponse } from '@/models/profile';
export async function uploadImageVariants(
uploadInit: ImageUploadInitResponse,
blobs: { original: Blob; small: Blob },
): Promise<void> {
for (const instruction of uploadInit.uploads) {
const blob = instruction.variant === 'ORIGINAL' ? blobs.original : blobs.small;
let response: Response;
try {
response = await fetch(instruction.url, {
method: instruction.method,
mode: 'cors',
headers: instruction.headers,
body: blob,
});
} catch (err) {
if (err instanceof TypeError) {
throw new Error(
'Image upload was blocked before reaching storage. Check Spaces CORS allows PUT from this web origin with Content-Type, Cache-Control, and x-amz-acl headers.',
);
}
throw err;
}
if (!response.ok) {
throw new Error(`Image upload failed (${instruction.variant}, ${response.status}).`);
}
}
}
|