Hi Daniel,

you should see:
http://docs.python.org/library/bz2.html#module-bz2

<http://docs.python.org/library/bz2.html#module-bz2>or
http://docs.python.org/library/gzip.html#module-gzip

But basically you should import the compress function from the library and
use it.

<http://docs.python.org/library/gzip.html#module-gzip>from bz2 import
compress

[...]


def handle_uploaded_subtitles(self, files):
   for file in files:
       sub_file = SubtitleFile(file_name=file.name, etc)
       bz_file = compress(file)
       sub_file.file.save(file.name, bz_file)

Regards,

On Tue, Apr 19, 2011 at 7:36 PM, Daniel Gerzo <dge...@gmail.com> wrote:

> Hello all,
>
> I am uploading some text files through django (using a form FileField), and
> I am getting InMemoryUploadedFile objects this way. In my
> handle_uploaded_subtitles() method, which gets the list of
> InMemoryUploadedFile objects, I would like to compress these files (so that
> I will get either gzip or bzip2 file, and then save it to a FileField model
> field.
>
> Currently, I have a this code:
>
> def handle_uploaded_subtitles(self, files):
>    for file in files:
>        sub_file = SubtitleFile(file_name=file.name, etc)
>        # here I need to compress the file
>        sub_file.file.save(file.name, file)
>
> Does anyone here have an idea how can I accomplish this?
> Thanks!
>
> --
> Kind regards
>  Daniel
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Julio Ona

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to