Closed karladler closed 7 years ago
See if the answer to your preview issue (#24) helps with that.
Thanks, I already found that it's possible to set the fileSize limit using const {files, fields} = await asyncBusboy(ctx.req, {limits: fileSize: 1000}});
but this will actually truncate the file only to the given limit. I wan't to know wether the file exceeds the limit while writing. I'm currently checking after reading the files whether the file size is exactly the limit e.g. 1000
.
It work's in practice but theoretically you can't say whether the file has exactly 1000 bytes or it's a bigger file. That's why I would be happy to have an exception thrown like described above.
Hi, I've just merged #18 which allow setting a custom handler for onFile
, it should work for your use case. See the doc:
If a custom onFile handler is specified in the options to async-busboy it will only resolve an object containing fields, but instead no temporary files needs to be created since the file stream is directly passed to the application. Note that all file streams need to be consumed for async-busboy to resolve due to the implementation of busboy. If you don't care about a received file stream, simply call stream.resume() to discard the content.
This should do it. Thank you!
Would it be possible to implement the file.on('limit') event? I would really like to have an error thrown like shown below or exposing the listeners or having same options for callbacks, not sure what would be the best practice here...