Spring Boot GraphQL Tutorial #13 - File Upload

Опубликовано: 29 Сентябрь 2024
на канале: Philip Starritt
11,245
88

GraphQL Spring Boot fully supports file uploading via multi-part file upload.

In your resolver you can get access to a list of Parts via the DataFetchingEnvironment context. You can then get the file's name, size and more importantly its content via the inputstream.

When accepting files from users, please follow the following file upload best practices:
https://cheatsheetseries.owasp.org/ch...

I recommend you read the following article explaining file risks: https://owasp.org/www-community/vulne...

If you need to buffer the files content into bytes/memory, then I recommend you limit this to a maximum number of concurrent invocations. This will stop the app from crashing with an out-of-memory error if large numbers are uploaded at the same time.

You can adjust tomcats maximum file multipart size with the following properties:
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

Cheers,
Philip!

Spring Boot GraphQL: https://github.com/graphql-java-kicks...

Learn GraphQL: https://graphql.org/learn/


Thumbnail: https://www.kindpng.com/imgv/ixThxib_...