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');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -125,6 +125,11 @@
|
|||
"type": "file",
|
||||
"system": false,
|
||||
"required": true,
|
||||
"maxSelect": 1,
|
||||
"maxSize": 20971520,
|
||||
"mimeTypes": ["image/jpeg", "image/png", "image/webp", "image/gif", "image/svg+xml"],
|
||||
"thumbs": ["300x300", "1200x0"],
|
||||
"protected": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
|
|
@ -140,7 +145,7 @@
|
|||
"1200x0"
|
||||
],
|
||||
"maxSelect": 1,
|
||||
"maxSize": 10485760,
|
||||
"maxSize": 20971520,
|
||||
"protected": false
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue