Skip to content

Instantly share code, notes, and snippets.

@abithyzis
Created February 16, 2016 12:31
Show Gist options
  • Select an option

  • Save abithyzis/f18d8ddd980ce0e53d3d to your computer and use it in GitHub Desktop.

Select an option

Save abithyzis/f18d8ddd980ce0e53d3d to your computer and use it in GitHub Desktop.
Django AppEngine compatible url to ImageField
import requests
from StringIO import StringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
response = requests.get(url)
img_io = StringIO(response.content)
thumb_file = InMemoryUploadedFile(img_io, None, file_name, 'image/jpeg', img_io.len, None)
new_video = Video()
new_video.thumb.save(file_name, thumb_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment