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 16396,Validation Problem Reading Files When Using Custom Storage Module,dadealeus@…,nobody,"Using a custom storage module I wrote using the Rackspace CloudFiles API, if I perform any sort of reads on a file object during custom validation of uploaded files, I need to seek back the beginning of the file before I return it as cleaned_data. Example form class: {{{ class UploadImageForm(forms.Form): """""" Form to handle design uploads """""" design = forms.ImageField(error_messages={'required' : ""Please select an image to upload.""}) def clean_design(self): from generic.media import utils # Verify uploaded image is an image data = self.cleaned_data['design'] # Open the image so we can autocrop before checking dimensions image = PIL.open(StringIO(data.read())) # Autocrop the image and then check the dimensions image = utils.autoCrop(image) # Minimum image size min_image_size = 90 # Verify the image size width, height = image.size width = float(width) height = float(height) ratio = height / width # Perform various validation checks... Example: if (ratio > 16) or (ratio < 0.0625): raise forms.ValidationError(""The uploaded image's aspect ratio is too extreme. Please use an image that looks more square."") return data }}} Upon trying to save an image with the cleaned data (while using my custom storage module) via a custom view, the file object has no data associated with it unless I seek back to 0 before returning the cleaned data. Please note that this only occurs when using my custom storage module and when performing custom validation on the uplodaded data. Using the native django storage, the exact same code functions without any issues. I would like to see a note added to the custom storage documentation that specifies something like: ""If performing custom validation on a file object while using a custom storage module, be sure to seek back to zero before passing back the cleaned data as the file object is returned in its current state. Example: {{{ class UploadImageForm(forms.Form): """""" Form to handle image uploads """""" image = forms.ImageField(error_messages={'required' : ""Please select an image to upload.""}) def clean_image(self): data = self.cleaned_data['image'] stringIO = data.read() # Perform some custom validation # Reset the file object before returning it as cleaned data data.seek(0) return data }}} """,Bug,closed,Documentation,1.3,Normal,invalid,validation storage custom,,Unreviewed,0,0,0,0,0,0