Notes: This calls the public endpoint directly and should not include any Authorization header. Uploads are rate-limited.
async function publicUpload({ apiBase, projectPublicId, uploadPreset, file, apiKey }) {
const url = apiBase + '/p/' + projectPublicId + '/images';
const fd = new FormData();
fd.append('upload_preset', uploadPreset);
fd.append('file', file);
if (apiKey) fd.append('api_key', apiKey);
const res = await fetch(url, { method: 'POST', body: fd });
if (!res.ok) throw new Error(await res.text());
return res.json();
}