jaydenseric / graphql-upload

Middleware and a scalar Upload to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 132 forks source link

how to handle maxFileSize errors with graphqlUploadExpress #235

Closed rafinskipg closed 3 years ago

rafinskipg commented 3 years ago

Hello, sorry if this is a duplicate, i didn't found it.

How one can handle the maxFileSize error with express?

I am seeing this error

UnhandledPromiseRejectionWarning: PayloadTooLargeError: File truncated as it exceeds the 100000 byte size limit.

But I don't see how to attach any callback to the graphqlUploadExpress

Thanks

jaydenseric commented 3 years ago

Are you handling file upload stream errors?

https://github.com/jaydenseric/apollo-upload-examples/blob/be1444a0aa8768c6fe2e2c96119eb2b6344fcc50/api/server.js#L43-L54

rafinskipg commented 3 years ago

How do you handle the file upload stream errors?

I just followed the documentation:

app.use(graphqlUploadExpress({ maxFileSize: 1000000, maxFiles: 10 }));
jaydenseric commented 3 years ago

@rafinskipg I linked an example in the previous comment.

rafinskipg commented 3 years ago

I'm sorry but it does not seem to work with my current set-up.

It seems that the error is launched when createReadStream because the file is bigger than the size. Anyway, wrapping createReadStream with a try/catch seems to work for me! Thanks Mr jaydenseric. May the force be with you

akristmann commented 2 years ago

I'm sorry but it does not seem to work with my current set-up.

It seems that the error is launched when createReadStream because the file is bigger than the size. Anyway, wrapping createReadStream with a try/catch seems to work for me! Thanks Mr jaydenseric. May the force be with you

I had the same problem and this was the only solution that worked for me. Thank you Rafin!