fixed image upload
This commit is contained in:
parent
96828994e1
commit
fd1afc5f3a
3 changed files with 10 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ export async function uploadMedia(file: File) {
|
|||
formData.append('file', file);
|
||||
formData.append('alt', file.name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
|
||||
|
||||
const res = await fetch('/admin/api/upload', { method: 'POST', body: formData });
|
||||
const res = await fetch('/api/upload', { method: 'POST', body: formData });
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
throw new Error(err?.message || `Upload failed (${res.status})`);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
|||
return json({ record, url });
|
||||
} catch (e) {
|
||||
console.error('Media upload error:', e);
|
||||
throw error(500, 'Upload failed');
|
||||
// Surface PocketBase's field validation message (e.g. file too large, wrong type)
|
||||
const fieldError = (e as { response?: { data?: Record<string, { message?: string }> } })?.response?.data?.file?.message;
|
||||
throw error(fieldError ? 400 : 500, fieldError ? `Upload failed: ${fieldError}` : 'Upload failed');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue