Created
October 24, 2015 20:57
-
-
Save edgabaldi/3b23f689353d9d2a7cb2 to your computer and use it in GitHub Desktop.
Download photo with requests and saving in Django ImageField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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