On Wednesday, 8 June 2011 20:40:35 UTC+1, Greg Donald wrote: > > I have a model EventType that has an ImageField named image. > > When I post my image upload form I can upload an image with no problems. > > > But when I try to save() an image from the file system I get the error: > > 'str' object has no attribute 'chunks' > > > Here is my code: > > et = EventType( name=name ) > et.save() > > image_name = "%s.png" % name > image_path = "%s/images/%s.png" % ( settings.MEDIA_ROOT, name ) > image_file = open( image_path, 'rb' ) > > et.image.save( image_name, image_file.read() ) > > > I'm sure the file exists and is readable. > > I'm not sure why image_file.read() is returning a str, it spews a > bunch of what appears to be image data when I debug it. > > Any idea what I'm doing wrong? > > > Thanks. > But that "bunch of image data" is a string - because that's what .read() returns.
The FileField documentation [1] shows how to save a disk file to a field: from django.core.files import File f = open('/tmp/hello.world') myfile = File(f) et.image.save( image_name, myfile ) https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.FieldFile.save -- DR. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/QnhPeHYwUkp3QXdK. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.