When sending REST API requests with multipart/form-data, e.g. PATCH or POST within the admin panel, a request body larger than 1MB throws the following error: ``` Unterminated string in JSON at position... ``` This is because there are sensible defaults imposed by the HTML form data parser (currently using [busboy](https://github.com/fastify/busboy)). If your documents exceed this limit, you may run into this error when editing them within the admin panel. To support large documents over 1MB, use the new `bodyParser` property on the root config: ```ts import { buildConfig } from 'payload' const config = buildConfig({ // ... bodyParser: { limits: { fieldSize: 2 * 1024 * 1024, // This will allow requests containing up to 2MB of multipart/form-data } } } ``` --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211317005907885
17 lines
401 B
TypeScript
17 lines
401 B
TypeScript
export function getFormDataSize(formData: FormData) {
|
|
const blob = new Blob(formDataToArray(formData))
|
|
return blob.size
|
|
}
|
|
|
|
function formDataToArray(formData: FormData) {
|
|
const parts = []
|
|
for (const [key, value] of formData.entries()) {
|
|
if (value instanceof File) {
|
|
parts.push(value)
|
|
} else {
|
|
parts.push(new Blob([value], { type: 'text/plain' }))
|
|
}
|
|
}
|
|
return parts
|
|
}
|