Skip to content

Instantly share code, notes, and snippets.

@thenationofalex
Created October 29, 2016 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenationofalex/2ebe8f38ebe7848d75c4c7ee5492a6be to your computer and use it in GitHub Desktop.
Save thenationofalex/2ebe8f38ebe7848d75c4c7ee5492a6be to your computer and use it in GitHub Desktop.
GraphQL/Graphene Django - Uploading files.
#!/usr/bin/env python3
'''
Since Django's request isn't avaliable to graphene's mutation def.
It is passed in via context.
'''
import graphene
from .models import Users
class UploadMutation(graphene.Mutation):
class Input:
id = graphene.String()
profileImage = graphene.String()
def mutate(self, input, context, info):
id = input.get('id')
user = Users.objects.get(pk=id)
if context.FILES and context.method == 'POST':
user.image = context.FILES['profileImage']
user.save()
return UploadMutation(user=user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment