I've got a form with 20 ImageFields - such a form for sending photos
to the site admin as a request for a new user. Well, Django certainly
handles and uploads the, that's OK. But when it comes to sending all
the files as an attachment - I got stuck.
Here's a simple example of how I tried to do that:
------------------------------------------------
from django.core.mail import EmailMessage
email = EmailMessage()
for (k, v) in request.FILES.items():
email.attach(v.name, v.read())
------------------------------------------------
Small files are read nicely. But when someone "clever" fills out all
the form files (all the twenty) with images each one at least 10 Mb -
Django consumes so much memory... so I'm not in knowledge to handle
that.
Please, guide me how to handle big files from a form and send them
without memory leaks. Thanks ahead.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
> Small files are read nicely. But when someone "clever" fills out all
> the form files (all the twenty) with images each one at least 10 Mb -
> Django consumes so much memory... so I'm not in knowledge to handle
> that.
Hi,
email is not really suitable for sending large amounts of data. The
fact that people use it that way is a bit sad, but you should not
really follow their example.
So, you're trying to send up to 200 MB via email. That's in fact
some 270 MB, because binary data is base64 encoded in emails,
typically (not always, but often). That is the reason for the memory
problem.
As Paulo pointed out, created a unique, temporary URL for
downloading those images and send just the link to that URL.
HTH
Jirka
Another question that bothers me is the following.
-------------------------------------------------------------
for (k, v) in request.FILES.items():
file_data = open('%s/%s' % (dir, filename), 'wb')
file_data.write(v.read())
file_data.close()
-------------------------------------------------------------
That's not all the loop but that's enough to understand that I write
uploaded files to another location to give a link in e-mail.
I'm not really sure if it's correct - the files after upload are saved
to temp directory or RAM, but I actually read them again "v.read()" to
save to another loaction. Is that ok? Is there other way to save
uploaded files without reading them again?
Thanks.
On Mar 18, 8:19 pm, Jirka Vejrazka <jirka.vejra...@gmail.com> wrote:
> > I've got a form with 20 ImageFields - such a form for sending photos
> > to the site admin as a request for a new user. Well, Django certainly
> > handles and uploads the, that's OK. But when it comes to sending all
> > thefilesas an attachment - I got stuck.
> > Smallfilesare read nicely. But when someone "clever" fills out all
> > the formfiles(all the twenty) with images each one at least 10 Mb -
> > Django consumes so much memory... so I'm not in knowledge to handle
> > that.
>
> Hi,
>
> emailis not really suitable for sendinglargeamounts of data. The
> fact that people use it that way is a bit sad, but you should not
> really follow their example.
>
> So, you're trying to send up to 200 MB viaemail. That's in fact
When a-mailng files are uploaded to RAM anyway, zipping files just
don't really help on binary data. I chosed to save them to a web-
visible location.
On Mar 18, 7:59 pm, Paulo Almeida <igcbioinformat...@gmail.com> wrote:
> I can't help you with the technical part, but a couple of suggestions:
>
> * Sum the size of the images and send two (or more) e-mails if it exceeds a
> threshold
> * Forget attachments and just zip the images and make them accessible in an
> URL that is e-mailed to the site admin
>
> - Paulo
>
> On Wed, Mar 17, 2010 at 8:57 AM, tezro <tezro...@gmail.com> wrote:
> > Hello everyone. I need some help or advice.
>
> > I've got a form with 20 ImageFields - such a form for sending photos
> > to the site admin as a request for a new user. Well, Django certainly
> > handles and uploads the, that's OK. But when it comes to sending all
> > the files as an attachment - I got stuck.
>
> > Here's a simple example of how I tried to do that:
> > ------------------------------------------------
> > from django.core.mail import EmailMessage
>
> > email = EmailMessage()
> > for (k, v) in request.FILES.items():
> > email.attach(v.name, v.read())
> > ------------------------------------------------
>
> > Small files are read nicely. But when someone "clever" fills out all
> > the form files (all the twenty) with images each one at least 10 Mb -
> > Django consumes so much memory... so I'm not in knowledge to handle
> > that.
>
> > Please, guide me how to handle big files from a form and send them
> > without memory leaks. Thanks ahead.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users...@googlegroups.com<django-users%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to django-users...@googlegroups.com.
On Mar 19, 5:20 pm, Paulo Almeida <igcbioinformat...@gmail.com> wrote:
> Hi,
>
> My suggestion to zip the files was to provide a single download link with
> all the files.
>
> - Paulo
>
> > <django-users%2Bunsu...@googlegroups.com<django-users%252Buns...@googlegroups.com>
To unsubscribe from this group, send email to django-users...@googlegroups.com.