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, {
|
const response = await fetch(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
...(useProxy && {
|
// Don't set Content-Type manually - browser will set it with boundary automatically
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@ -24,15 +24,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse multipart form data
|
// Parse multipart form data
|
||||||
|
// formidable needs the raw Node.js IncomingMessage, which NextApiRequest extends
|
||||||
const form = new IncomingForm({
|
const form = new IncomingForm({
|
||||||
maxFileSize: MAX_FILE_SIZE,
|
maxFileSize: MAX_FILE_SIZE,
|
||||||
keepExtensions: true,
|
keepExtensions: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const parseResult = await new Promise<ParseResult>((resolve, reject) => {
|
const parseResult = await new Promise<ParseResult>((resolve, reject) => {
|
||||||
form.parse(req, (err, fields, files) => {
|
// Cast req to any to work with formidable - NextApiRequest extends IncomingMessage
|
||||||
if (err) reject(err)
|
form.parse(req as any, (err, fields, files) => {
|
||||||
else resolve({ fields: fields as Record<string, string[]>, files: files as Record<string, FormidableFile[]> })
|
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