We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I use nuxt for my api. I am only reading a password from a post request body. But if I upload a large file (>2GB) it loads everything into ram.
Is there a way to close the request after e.g. 1kb?
The text was updated successfully, but these errors were encountered:
import Busboy from 'busboy'; export default defineEventHandler(async (event) => { return new Promise((resolve, reject) => { const busboy = new Busboy({ headers: event.req.headers }); let password = null; let fileProcessed = false; busboy.on('field', (fieldname, value) => { if (fieldname === 'password') { password = value; } }); busboy.on('file', (fieldname, file, filename, encoding, mimetype) => { if (!fileProcessed) { fileProcessed = true; file.on('limit', () => { const error = new Error('File size exceeds the limit.'); error.statusCode = 413; // Payload Too Large reject(error); file.destroy(error); }); file.on('data', (chunk) => {f file.destroy(new Error('File upload aborted.')); }); file.on('end', () => { file.destroy(); }); file.on('error', (err) => { reject(err); file.destroy(err); }); } else { file.destroy(new Error('Multiple files are not allowed.')); } }); busboy.on('finish', () => { if (password) { resolve({ password }); } else { reject(new Error('Password field is missing.')); } }); busboy.on('error', (err) => { reject(err); }); event.req.pipe(busboy); }); });
Sorry, something went wrong.
No branches or pull requests
Describe the feature
I use nuxt for my api.
I am only reading a password from a post request body. But if I upload a large file (>2GB) it loads everything into ram.
Is there a way to close the request after e.g. 1kb?
Additional information
The text was updated successfully, but these errors were encountered: