2013/3/4 msoulier <[email protected]>
> Hi,
>
> I'm using a ModelForm to upload a large file that ends up being
> written to a tempfile on disk. When I call form.save(), the file gets
> copied to the final filename, but the tempfile is left behind on disk.
>
> I am using a custom handler, which is a TemporaryFileUploadHandler
> subclass, but each method I override calls the parent class' method
> first.
>
> Is the tempfile supposed to be left behind?
>
> Thanks
>
> Hello,
I am not an experienced django developer so maybe this solution doesnt
follow 'the django way', but as i read at:
http://docs.nullpobug.com/django/trunk/django.core.files.uploadhandler-pysrc.html#FileUploadHandler.new_file
TemporaryFileUploadHandler subclass FileUploadHandler. The 'new_file'
method at FileUploadHandler saves
the file name at the class instance as 'file_name' (self.file_name). So, i
would try to overrite the 'file_complete'
method from my own class that subclass TemporaryFileUploadHandler and do
something like:
class MyTemporaryFileUploadHandler(TemporaryFileUploadHandler):
def file_complete(self, file_size):
if os.path.isfile(self.file_name):
os.unlink(self.file_name)
super(TemporaryFileUploadHandler, self).file_complete(file_size)
I'm not sure if self.file_name points to the temporary file, so maybe this
is not util.
--
"Code without tests is broken by design." - Jacob Kaplan-Moss
Show me the mone ... code!: https://bitbucket.org/edvm
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.