Spring Boot GraphQL Tutorial #13 - File Upload

preview_player
Показать описание
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:

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:

Cheers,
Philip!

Рекомендации по теме
Комментарии
Автор

@Philip Thanks for the tutorials. Can you please make one video how to download file using GraphQL?

abhishekbansal
Автор

Hi Philip, great job, just wanted to add an update: since getContext() has been deprecated, here is how get the file.

@Slf4j
@Component
public class UploadFileMutation implements GraphQLMutationResolver {
public UUID environment) throws IOException, ServletException {
log.info("---- Uploading file.");

HttpServletRequest context =
context.getParts().forEach(
part -> {
if {
log.info("---- Uploading: file name={}, size={}", part.getSubmittedFileName(), part.getSize());
}
});

return UUID.randomUUID();
}
}

nefistofeles
Автор

Hi Philip,
Did you ever experience a 422 UNPROCESSABLE_ENTITY with this implementation? Or do you have an idea what the issue could be.

thomasvandriessche
Автор

Thanks a lot! You are genius teacher, everything works and I can now upload my images with Graphql, cool

alexanderlepekhin
Автор

{
"timestamp": "2023-04-21T11:06:05.251+00:00",
"status": 404,
"error": "Not Found",
"path": "/graphql"
}

I'm getting this can anyone help ?

vip
Автор

how can I upload the file using apollo client? I would like to make use of current refresh token algorithm

cescoferraro
Автор

I am getting this error after send post request from postman: g.abstractGraphQlhttpservlet: bad POST multipart request: no part named graphql or query?

abhishekbesoya
Автор

@Philip Starritt thank you very much for the video, I have one question though .I have tried your method it all worked out when i tried it in Postman but now I want to use it in actual frond end which I have built using angular .So when i use this to I use apollo graphql to send the files or just use the post method of the http .if you can help me here it would be be very nice thanks

mohammedmohammed
Автор

Thanks! Just a simple idea to improve your next movies: could you please decrease the screen resolution when recording?

nicolasenzweiler
Автор

Hello, do you have something similar on webflux?

ruslan-macari
Автор

@Phillip Staritt, Can u share the pom.xml to see whcih graphql-libraries are using?

PradeepKeshavprakash
Автор

Your mutation signature has 1 argument (environment) and yet in mutation.grapqls you do not add this to the endpoint definition. Hence Im getting exception saying it looks for resolver without any argument and fails to find it. Any way around it?

crriidr
Автор

which version of graphQl are you using? i am not able to see DefaultGraphqlServletContext in my code, instead there is DefaultGraphQLContext but that fails

saurabhkala
Автор

Really helpful video, but I'm stuck on the query I try to imprement in js, what would be the equivalent of your query in graphql language please?

Ioan_S
Автор

Would this work on Netty server though? Since it uses the HttpServletRequest and response..
What can I do to make it work on Netty?

thushar
Автор

Hi Philip, Can u share a video for sftp the uploading file to a server using graphql ?

ayyasamys
Автор

Thanks! How would we do Integration testing for this feature?

mcroyy
Автор

Hi, can you please share git code reference for this file upload

ayyasamys
Автор

is this approach good for large files ? Around 1 GB ?

sergmayakov
join shbcf.ru