feat(frontend): POST for images
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
}
|
||||
|
||||
handle {
|
||||
request_body {
|
||||
max_size 50MB
|
||||
}
|
||||
reverse_proxy stealth-ai-relay-frontend:3000
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,21 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
|
||||
|
||||
if (rawContentType.includes('multipart/form-data')) {
|
||||
const formData = await request.formData();
|
||||
console.log('[POST /{mnemonic}] formData keys:', [...formData.keys()]);
|
||||
const keys = [...formData.keys()];
|
||||
console.log('[POST /{mnemonic}] formData keys:', keys);
|
||||
|
||||
const file = formData.get('file') || formData.get('image') || formData.values().next().value;
|
||||
if (!(file instanceof File)) {
|
||||
throw error(400, 'No file found in form data');
|
||||
let file: File | null = null;
|
||||
for (const key of ['file', 'image', 'photo', 'upload', 'attachment', ...keys]) {
|
||||
const value = formData.get(key);
|
||||
if (value instanceof File) {
|
||||
file = value;
|
||||
console.log('[POST /{mnemonic}] found file in field:', key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
throw error(400, `No file found in form data. Keys: ${keys.join(', ')}`);
|
||||
}
|
||||
|
||||
const buffer = await file.arrayBuffer();
|
||||
@@ -50,6 +60,8 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
|
||||
mediaType = detectImageType(bytes) || file.type || 'image/jpeg';
|
||||
|
||||
console.log('[POST /{mnemonic}] file:', file.name, file.type, 'size:', buffer.byteLength);
|
||||
} else if (rawContentType.includes('application/x-www-form-urlencoded')) {
|
||||
throw error(400, 'Use Form with File field, not URL-encoded form');
|
||||
} else {
|
||||
const buffer = await request.arrayBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
Reference in New Issue
Block a user