Try this:
# in your view
raw_image_data = form.cleaned_data['photo']['content']
thumbnail_content = resize_image(raw_image_data)
filename = form.cleaned_data['photo']['filename']
upload_to_s3(filename, thumbnail_content)

def resize_image(buf, size=(100, 100)):
    f = cStringIO.StringIO(buf)
    image = PILImage.open(f)
    if image.mode not in ('L', 'RGB'):
        image = image.convert('RGB')
    image.thumbnail(size, PILImage.ANTIALIAS)
    o = cStringIO.StringIO()
    image.save(o, "JPEG")
    return o.getvalue()

def upload_to_s3(filename, filedata):
    conn = S3.AWSAuthConnection(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
    content_type = mimetypes.guess_type(filename)[0]
    response = conn.put(BUCKET_NAME, '%s' % filename,
S3.S3Object(filedata), {'x-amz-acl': 'public-read', 'Content-Type':
content_type})

Regards, Sander.

On 31 mei, 17:38, Kyle Fox <[EMAIL PROTECTED]> wrote:
> I think my question wasn't clear:  we're having NO problem putting
> files on S3, that's dead simple (ie what Holovaty blogged about).
>
> What we need to do is take an *in-memory Image* and put it directly
> onto S3.  We need a way to convert a PIL Image instance into a format
> S3 can accept WITHOUT having to first save the Image to the file-
> system.  S3 accepts the kind of string that gets returned from
> open(afile).read()
>
> I was trying to wrap the result of img.tostring() in the StringIO
> class, and then put that on S3, but that doesn't work either...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to