Skip to content

Instantly share code, notes, and snippets.

@edgabaldi
Created October 24, 2015 20:57
Show Gist options
  • Select an option

  • Save edgabaldi/3b23f689353d9d2a7cb2 to your computer and use it in GitHub Desktop.

Select an option

Save edgabaldi/3b23f689353d9d2a7cb2 to your computer and use it in GitHub Desktop.
Download photo with requests and saving in Django ImageField
import requests
from StringIO import StringIO
from product.models import Product, Photo
from django.core.files.base import ContentFile
response = requests.get('http://photo-url/image.jpg')
file = StringIO(response.content)
file_content = ContentFile(file.read())
photo = Photo()
photo.file.save('filename.jpg', file_content)
photo.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment