Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Oct. 27, 2005 00:21:43

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom Manipulator File Upload


The world is different when you have a custom manipulator. It's more
beautiful, except I can't find any docs on them anywhere.

Here, I am uploading email in my custom manipulator using:

formfields.ImageUploadField(field_name="photo")

And showing it using {{ form.photo }} in my template which works
beautifully.

I was reading somewhere that I have to do:
new_data.update(request.FILES)
in my view, which I have no idea why, but I don't object to it either.

Lastly, I want to save it. Well... I know where my image is:
a = request.FILES

I can even view it: (How cool is that!!!)
return HttpResponse(a)

I know how to extract it's name:
request.FILES

Now,
1. How do I actually save this into a file?
2. I need to resize the image and play with it with PIL. Is it possible
to transfer the image to an image object without saving it and then
giving it's full path to load it?

Thank you in advance for your response,
Armin

Offline

#2 Oct. 27, 2005 03:17:30

Adrian H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom Manipulator File Upload


On 10/26/05, Armin <> wrote:
> The world is different when you have a custom manipulator. It's more
> beautiful, except I can't find any docs on them anywhere.

Agreed on both counts. They're much better than the default
manipulators -- and they need to be better documented. :)

> 1. How do I actually save this into a file?

Use Python file objects, like so:

"""
f = open('/path/to/output/file.jpg', 'wb') # wb = write binary
f.write(request.FILES)
f.close()
"""

> 2. I need to resize the image and play with it with PIL. Is it possible
> to transfer the image to an image object without saving it and then
> giving it's full path to load it?

I haven't tested this, but PIL's Image.open() function takes any
file-like object, so you might be able to pass it a StringIO proxy.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Offline

#3 Oct. 27, 2005 05:23:45

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom Manipulator File Upload


Thanks very much Adrian. It did the magic.
Armin

Offline

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support