Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload #141

Open
asoseil opened this issue Jun 24, 2016 · 15 comments
Open

File upload #141

asoseil opened this issue Jun 24, 2016 · 15 comments

Comments

@asoseil
Copy link

asoseil commented Jun 24, 2016

is there a way to upload files?

@schumajs
Copy link

schumajs commented Dec 8, 2016

Hi Alessio,

Have you by any chance figured out how to upload files?

Thanks and best,

Jens

@narqo
Copy link

narqo commented Dec 9, 2016

Why not ask the question on some of GraphQL Community Resources? I don't think there might be any technical issues related to Go implementation. You only need to figure out how the pattern applied GraphQL in general.

@bbuck
Copy link
Collaborator

bbuck commented Dec 9, 2016

An option here is to provide a standard endpoint for file uploads and route the user through it. With some iframe trickery (unless things have changed since I've done this) you can do "background" file uploads. Your file upload route is just a standard non-GraphQL endpoint and would store the file in some temporary (safe) location. It returns the filename. Then you submit your GraphQL request with the filename and the handler can access the file in the temporary location (or S3 or wherever it is).

edit

A secondary option might be to use middleware and have a handler situated in front of your GraphQL handler to process the multipart portion of the file and store it, making it accessible via context or any number of other means and then passing forward to the next handler in line, the GraphQL handler.

@schumajs
Copy link

schumajs commented Dec 9, 2016

Thanks for the answers. I followed the approach discussed here. Works pretty well.

@saveliy-kremen
Copy link

GraphQL multipart request specification allows you to nest files anywhere within GraphQL mutations like this:

{
query: mutation($file: Upload!) { uploadFile(file: $file) { id } },
variables: {
file: File // somefile.jpg
}
}
It would be nice to add a type to graphql *multipart.FileHeader to use it.

@jianjungki
Copy link

can you post your upload code for sharing? because i have got the same problem @schumajs

@glaslos
Copy link

glaslos commented Aug 2, 2018

There is a specification for handling multipart in graphql: https://github.com/jaydenseric/graphql-multipart-request-spec

@chienfuchen32
Copy link

@glaslos cool

@niondir
Copy link

niondir commented Sep 11, 2019

I'm also looking for file uploads.

Is there some working solution / example out there?

I will start with trying: https://github.com/jpascal/graphql-upload

@koblas
Copy link
Contributor

koblas commented Sep 16, 2019

FYI - this PR has been around for a long time to add support at the handler level

graphql-go/handler#43

@exapsy
Copy link

exapsy commented Aug 23, 2020

Any updates on this? Seems like its been literally a year ago since last post :P And there seems to be a PR hanging there for a year, which could potentially solve the problem altogether.

@koblas
Copy link
Contributor

koblas commented Aug 24, 2020

I'm happy updating the PR, but given that it's been 2 years of silence not racing to rebase until I have some indication that it'll be merged...

@bbuck
Copy link
Collaborator

bbuck commented Aug 26, 2020

I don't think that the GraphQL spec has any details about handling multi-part/file uploads. There is no reason you cannot have non-GraphQL endpoints along with GraphQL endpoints, like for uploading files.

In past projects, I've typically uploaded files directly to S3 and then passed the URL of said files down in the request to the server. This is great because then I don't have to concern my app with passing files through to S3 and also don't need to handle file uploads directly.

I can't find a reference to the spec that details handling file uploads so I don't see any reason to go off-spec for this spec-compliant implementation.

@koblas
Copy link
Contributor

koblas commented Aug 26, 2020

While I've not read the details, the Apollo team wrote up this in May 2020.

https://www.apollographql.com/blog/apollo-server-file-upload-best-practices-1e7f24cdc050/

Where the apollo-upload-client package is still a recommended option.

@bbuck
Copy link
Collaborator

bbuck commented Aug 27, 2020

Referring to the official GraphQL spec: https://spec.graphql.org/

I still think files should be handled outside of GraphQL endpoints.

edit: I do not speak for this project's owners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests