I'm trying to download an image file from a URL and then assign that image to a Django ImageField. I've followed the examples here and [here](
My model, in pertinent part, looks like this:
class Entity(models.Model):
logo = models.ImageField(upload_to=_getLogoPath,null=True)
The _getLogoPath callback is pretty simple:
def _getLogoPath(self,filename):
path = "logos/" + self.full_name
return path
The code for fetching and saving the image file is also straightforward as part of a custom django-admin command that I plan on running as a regularly scheduled cron job:
...
img_url = "http://path.to.file/img.jpg"
img = urllib2.urlopen(img)
entity.logo.save(img_filename,img,True)
...
When I run this, I get this error:
AttributeError: addinfourl instance has no attribute 'chunks'
I also tried adding read()
to the image but resulted in a similar error. I also tried writing the image to a temporary file and then trying to upload that, but I get the same error.