On Thu, Feb 12, 2009 at 1:26 PM, Robert <robertpet...@winterlionsoftware.com > wrote:
> > I'm am trying to build an application that handles several types of > uploads. Currently, it will work fine for .txt type files, but for > all other kinds of files, the file is truncated to about 3 KB. > > I have determined that the file gets truncated during the request. I > have included some sample code with comments to make it clear where > the file gets truncated. > > def testFormRequest(self): > > file = open('F:\\Sample Upload Files\\large_pdf.pdf') > If you are going to be doing things with binary files, particularly on Windows, you'll need to open them with the binary flag. This "truncation" is likely resulting from a x1A character present in the PDF file, which Windows file processing in text mode reads as end of file: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> f1 = open('t.bin') >>> f1.read() 'Text before end-of-file marker.\n' >>> f2 = open('t.bin','rb') >>> f2.read() 'Text before end-of-file marker.\r\n\x1a\r\nText after end-of-file marker.\r\n' >>> As you can see, in addition to the file being "truncated" at the \x1a byte, the \r chars were stripped out when read in text mode. That's good for an actual text file, but will cause data corruption for binary files. Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---