Skip to content

Instantly share code, notes, and snippets.

@neara
Forked from karmadonov/base64.py
Created February 6, 2014 07:54
Show Gist options
  • Save neara/8839980 to your computer and use it in GitHub Desktop.
Save neara/8839980 to your computer and use it in GitHub Desktop.
import base64
import cStringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
# ...
if request.POST.get('file') and request.POST.get('name'):
file = cStringIO.StringIO(base64.b64decode(request.POST['file']))
image = InMemoryUploadedFile(file,
field_name='file',
name=request.POST['name'],
content_type="image/jpeg",
size=sys.getsizeof(file),
charset=None)
request.FILES[u'file'] = image
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment