Coder Social home page Coder Social logo

File Upload about flask-graphql HOT 7 OPEN

graphql-python avatar graphql-python commented on September 3, 2024 1
File Upload

from flask-graphql.

Comments (7)

michaelkuty avatar michaelkuty commented on September 3, 2024
    def mutate(cls, info, **kwargs):

        file = info.context.files.get('file', None)

from flask-graphql.

hxuanhung avatar hxuanhung commented on September 3, 2024

@michaelkuty can you make it work with Apollo? I got "Must provide query string." error when trying to send multipart/form-data; to the server.

from flask-graphql.

michaelkuty avatar michaelkuty commented on September 3, 2024

In apollo you must use something like middleware or something else..

from flask-graphql.

hxuanhung avatar hxuanhung commented on September 3, 2024

hm, have you actually worked on it? I'm using https://github.com/jaydenseric/apollo-upload-client for a client that sends multipart/form-data to the server but it seems not working.

from flask-graphql.

rshk avatar rshk commented on September 3, 2024

Ok, just managed to get it to work with Apollo. The problem lies with incorrect handling of the multipart-encoded request, here: https://github.com/graphql-python/flask-graphql/blob/master/flask_graphql/graphqlview.py#L126-L127

I sub-classed the GraphQLView to properly handle multipart/form-data, as per the spec. I also created a custom scalar field that can be used for file uploads, so no need to get files out of info.context or flask.request.

https://gist.github.com/rshk/97fd7b444e48c60218addb2b64897572

This will work with the version of flask-graphql currently in pypi; I haven't tested whith the master version yet (but should still work).

I can open a PR with the changes (I have unit tests covering that place_files_in_operations too).

from flask-graphql.

hxuanhung avatar hxuanhung commented on September 3, 2024

Similar to https://github.com/lmcgartland/graphene-file-upload/blob/master/graphene_file_upload/__init__.py
We can change a few things like I mentioned in lmcgartland/graphene-file-upload#3 to make it work for Flask.

from flask-graphql.

rshk avatar rshk commented on September 3, 2024

See #51

from flask-graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.