﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8333	FileField upload of large files looping and failing	tapautler	nobody	"Tripped on this while trying to update photologue, testing a large zip file.
Then tried some of my own code and found that wasn't working with large files either.
Uploads work fine for 1 meg files
Tried 20meg files and it goes into an upload loop during the save.
Uploads the file, lets say ""BIG_FILE"", then ""BIG_FILE_"" and so on ""BIG_FILE_..._"" until it fails on a filename of 215+ characters.
All the files that are uploaded are complete and are not corrupt.
I'm running on Windows with Apache and mod_python.

MODEL

{{{
class UploadedDocument( models.Model ):
    file = models.FileField( upload_to = 'uploads/documents/')
    description = models.CharField( max_length=255, blank=True, help_text='Description of document.')
    uploaded_by = models.ForeignKey( User )
}}}

FORM

{{{
class DocumentField(forms.FileField): 
    def __init__(self, *args, **kwargs): 
        super(DocumentField, self).__init__(*args, **kwargs) 
        self.label = 'New File' 
        self.help_text = 'Select a doc, rtf, or pdf document'     

    def clean(self, data, UNKNOWN_FIELD): 
        f = super(DocumentField, self).clean(data)

        if data in (None, ''):
            "" Required=False and no data... ""
            return None
        file_types = ('application/msword', 'application/rtf', 'application/pdf') 
        file_exts = ('.doc', '.rtf', '.pdf') 
        if (not splitext(f.name)[1].lower() in file_exts) and (not data['content-type'] in file_types): 
            raise forms.ValidationError('Document types accepted: %s' % ' '.join(file_exts))
        return f

class UploadedDocumentForm(ModelForm):
    file = DocumentField(required=True, 
                         widget=forms.FileInput(attrs={'size':'80'}))
    description = forms.CharField(required=True,
                                  help_text=UploadedDocument._meta.get_field('description').help_text,
                                  widget=forms.Textarea(attrs={'style':'width:98%; height:3em;' }))
    
    class Meta:
        model = UploadedDocument
        fields = ( 'file', 'description')
}}}

VIEW (SAVE PIECE)

{{{
doc = UploadedDocument(uploaded_by = request.user)
doc.file.save(f.name, f, save=False)
doc.description = form.cleaned_data['description']
doc.save()
}}}
"		closed	File uploads/storage	dev		duplicate	filefield upload looping		Unreviewed	0	0	0	0	0	0
