Does anyone know of any examples on how to upload ...
# kgraphql
m
Does anyone know of any examples on how to upload a file with kgraphql?
j
Hi, uploading files is not part of the GraphQL spec, so this is not something that KGraphQL support and probably won't do anytime soon. But for other solutions I shared how I do it here: https://kotlinlang.slack.com/archives/CDS4UH4BB/p1597424351000400
m
For anyone following this, my solution was to base64 encode the image as a string and send it to my server which then decoded it into a byte stream and put it to s3/cloudfront. It seem performant enough
👍 1
j
Did you create a scalar for it also?
m
no
j
You could make use of the stringScalar for this. So on the backend you can still use the
File
type, but then on the frontend it would just use strings and you had to manually convert it there.
m
i will look into that
j
https://kgraphql.io/Reference/Type%20System/scalars/ So you just need to make sure that you are able to serialize and deserialize it there. Then you can just return the
File
to the client and KGraphQL will make sure that it will use the serialization that you defined.
It's still not native support for file upload, but it's a fine solution that could be based on the same one that you came with.