Fix multipart parsing in NIP-95 upload proxy by removing manual Content-Type header and improving error handling
This commit is contained in:
parent
970f8761ac
commit
7bab834f89
@ -77,11 +77,7 @@ async function tryUploadEndpoint(endpoint: string, formData: FormData, useProxy:
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
...(useProxy && {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}),
|
||||
// Don't set Content-Type manually - browser will set it with boundary automatically
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@ -24,15 +24,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
try {
|
||||
// Parse multipart form data
|
||||
// formidable needs the raw Node.js IncomingMessage, which NextApiRequest extends
|
||||
const form = new IncomingForm({
|
||||
maxFileSize: MAX_FILE_SIZE,
|
||||
keepExtensions: true,
|
||||
})
|
||||
|
||||
const parseResult = await new Promise<ParseResult>((resolve, reject) => {
|
||||
form.parse(req, (err, fields, files) => {
|
||||
if (err) reject(err)
|
||||
else resolve({ fields: fields as Record<string, string[]>, files: files as Record<string, FormidableFile[]> })
|
||||
// Cast req to any to work with formidable - NextApiRequest extends IncomingMessage
|
||||
form.parse(req as any, (err, fields, files) => {
|
||||
if (err) {
|
||||
console.error('Formidable parse error:', err)
|
||||
reject(err)
|
||||
} else {
|
||||
resolve({ fields: fields as Record<string, string[]>, files: files as Record<string, FormidableFile[]> })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user