Re: [Catalyst] PDF upload problems (prob OT)?
Hi. Following up here after some time on another project. --- On Fri, 11/7/08, Joel Bernstein [EMAIL PROTECTED] wrote: From: Joel Bernstein [EMAIL PROTECTED] Subject: Re: [Catalyst] PDF upload problems (prob OT)? To: The elegant MVC web framework catalyst@lists.scsys.co.uk Date: Friday, November 7, 2008, 5:01 PM 2008/11/8 Dermot [EMAIL PROTECTED] 2008/11/7 Dr. Jennifer Nussbaum [EMAIL PROTECTED]: Anyone willing to help me on this? :-) Im only missing four bytes, somewhere Or adding them rather. Jen. I can't test this from where I am writing but as Adeola says. Open a temporary FH, binmode it, pour the content in. Then under MP2 you would $r-sendfile($tmpfh); content_type is 'application/pdf' I guess the Cat alternative would be $res-write( $tmpfh ); but you'd want to check that :) I'd use $c-response-body( $filehandle ) to achieve this. I'm not sure what you're expecting -write() to do there. How do i do this given that im pulling the data from a database? That is, my view' method is mostly like my $document = $c-model-find($id); my $contents = $document-documment; $c-res-output($contents); $c-res-headers-content_type($document-type); How do i make this binary? Also, in a separate message T0m Doran wrote, responding to my observation tht i had been gaining 4 bytes in size: -- I'd be prepared to bet that you're appending 4 bytes somewhere, either at the start, or the end of the document.. So have a look, and tell us which? Then start adding some debug, so your code becomes: my $upload = $c-request-upload('document'); my $contents = $upload-slurp; $c-log-debug(Uploaded file was . length($contents) . bytes); my $document = $c-model-create({ document = $contents, type = $upload-type, filename = $upload-basename}); and my $contents = $document-document; $c-log-debug(Document contents were . length($contents) . bytes); $c-res-output($contents); $c-res-headers-content_type($document-type); I did try this and discovered that this problem isnt consistent. at least riht now, im looking at one particular file that is problematic. It concistently looks fine with Evince on the commandline, and consistently looks bad with Evince in the browser piped through the database. I have added this debug code, and discovered that for this file it is always 9 bytes. Thats what it is in the filesystem before i upload it, thats what it is when Cat reports it as T0m suggest i do above, and thats what it is when Cat outputs it again as described above. But the output is messed up--still visible but with errors throughout, as if someone had written it on a blackboard and erased parts and shifted other parts. so maybe the four byte extra is a different issue? I cant replicate it at least for this file. So maybe its a binmode thing after all? How do i force it to output as binary? Thanks and sorry for the long delay! Jen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] PDF upload problems (prob OT)?
On 27 Nov 2008, at 12:51, Dr. Jennifer Nussbaum wrote: I have added this debug code, and discovered that for this file it is always 9 bytes. Thats what it is in the filesystem before i upload it, thats what it is when Cat reports it as T0m suggest i do above, and thats what it is when Cat outputs it again as described above. But the output is messed up--still visible but with errors throughout, as if someone had written it on a blackboard and erased parts and shifted other parts. so maybe the four byte extra is a different issue? I cant replicate it at least for this file. So maybe its a binmode thing after all? How do i force it to output as binary? Ok, next thing to try is to capture the HTTP request and response being made. You can then replay that HTTP request to see if it reliably creates the same problem, and also inspect the contents before it gets to the browser to check where the corruption is happening. I'd recommend using Paros (http://www.parosproxy.org/) for this - it's got nice features to trap requests and alter their contents. Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] PDF upload problems (prob OT)?
--- On Thu, 11/27/08, Tomas Doran [EMAIL PROTECTED] wrote: From: Tomas Doran [EMAIL PROTECTED] Subject: Re: [Catalyst] PDF upload problems (prob OT)? To: [EMAIL PROTECTED] Cc: The elegant MVC web framework catalyst@lists.scsys.co.uk, [EMAIL PROTECTED] Date: Thursday, November 27, 2008, 5:13 AM On 27 Nov 2008, at 12:51, Dr. Jennifer Nussbaum wrote: I have added this debug code, and discovered that for this file it is always 9 bytes. Thats what it is in the filesystem before i upload it, thats what it is when Cat reports it as T0m suggest i do above, and thats what it is when Cat outputs it again as described above. But the output is messed up--still visible but with errors throughout, as if someone had written it on a blackboard and erased parts and shifted other parts. so maybe the four byte extra is a different issue? I cant replicate it at least for this file. So maybe its a binmode thing after all? How do i force it to output as binary? Ok, next thing to try is to capture the HTTP request and response being made. You can then replay that HTTP request to see if it reliably creates the same problem, and also inspect the contents before it gets to the browser to check where the corruption is happening. This is really cool and i didnt know you could do this! I installed Paros and have played around with it. Unfortunatly i cant figure out what is happening, still. My reponse headers look like this: --- HTTP/1.0 200 OK Connection: close Date: Thu, 27 Nov 2008 14:36:52 GMT Content-Length: 93341 Content-Type: application/pdf Set-Cookie: session=7eccab441f14e3d142a072a231c66e51e5b91598; path=/; expires=Thu, 27-Nov-2008 15:36:52 GMT Status: 200 X-Catalyst: 5.7014 - Which seems OK to me, i guess, though the Content-Length isnt the same as what Cat is reporting for the output, which is 9, same as the file size. (I guess thats from headers) The PDF itself looks like the PDF i can view in the terminal. It begins --- %PDF-1.4 %âãÏÓ 8 0 obj /N 1 /Filter /FlateDecode /Alternate /DeviceGray /Length 631 stream --- and it ends --- 092712 0 n trailer /Info 11 0 R /Root 10 0 R /Size 12 /ID [3bf4386624f3e774819afb5b8dfa18af669eeb717392a42f4903bdf458b7f775] startxref 92936 %%EOF - both of which match what i see when i look at the thing itself. So im not really sure where to go from here. I can report that the effect is the same with Epiphany, Firefox, and Opera. Jen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] PDF upload problems (prob OT)?
On 6 Nov 2008, at 16:04, Dr. Jennifer Nussbaum wrote: Theres a length difference when i download. A test file i uploaded is 165681 bytes, but when i upload and save it to the database, and then display the file from my app and save it, its 165685 bytes-- four more. What should i be looking at to try to figure this out? Break the problem down into smaller pieces. I have two lines of attack to offer: What are the first few, and the last few bytes of the input and output files? I'd be prepared to bet that you're appending 4 bytes somewhere, either at the start, or the end of the document.. So have a look, and tell us which? Then start adding some debug, so your code becomes: my $upload = $c-request-upload('document'); my $contents = $upload-slurp; $c-log-debug(Uploaded file was . length($contents) . bytes); my $document = $c-model-create({ document = $contents, type = $upload-type, filename = $upload-basename}); and my $contents = $document-document; $c-log-debug(Document contents were . length($contents) . bytes); $c-res-output($contents); $c-res-headers-content_type($document-type); Which should tell you which end (input or output) you're gaining your bytes at... Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] PDF upload problems (prob OT)?
Hi. Last month i had some questions about uploading PDF's in a Catalyst app, and J. Shirley gave me some helpful advice. I got it working, or so i thought, and then put the project aside as the users werent ready for it. I just got back to it and i see that theres some kind of problem. The PDF's when displayed in my app are mangled; they are visible but there are display problems with them (parts cut off, or the image shifted). I dont know if it was like this originally and i just didnt notice, or if something has changed, but i dont know where to look and would be greatful for a push in the right direction. Im storing them in a MySQL database, with the PDF field a MEDIUMBLOB so large enough for a 16M file. My upload code is basically: my $upload = $c-request-upload('document'); my $document = $c-model-create({ document = $upload-slurp, type = $upload-type, filename = $upload-basename}); And then my display code is: # $document is already grabbed from the database $c-res-output($document); # overloaded to stringify to $document-document $c-res-headers-content_type($document-type); $c-res-headers-header('Content-Disposition' = 'attachment; filename=.$document-filename); (As another question, is this the right way to get the filename to the browser? The docs for HTTP::Headers didnt say anything about this.) Theres a length difference when i download. A test file i uploaded is 165681 bytes, but when i upload and save it to the database, and then display the file from my app and save it, its 165685 bytes--four more. What should i be looking at to try to figure this out? Thanks. Jen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re[2]: [Catalyst] PDF upload problems (prob OT)?
On Thu, November 6, 2008 8:04 am, Dr. Jennifer Nussbaum wrote: # $document is already grabbed from the database $c-res-output($document); # overloaded to stringify to $document-document My feeling is that you are treating the output as text when in fact a PDF file is a binary file. HTH, Christopher Taranto ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] PDF upload problems (prob OT)?
Christopher Taranto wrote: --- On Thu, 11/6/08, Dr. Jennifer Nussbaum [EMAIL PROTECTED] wrote: And then my display code is: # $document is already grabbed from the database $c-res-output($document); # overloaded to stringify to $document-document $c-res-headers-content_type($document-type); $c-res-headers-header('Content-Disposition' = 'attachment; filename=.$document-filename); My feeling is that you are treating the output as text when in fact a PDF file is a binary file. Im not clear on how to treat it different. The Catalyst::Response docs dont say anything about how to do this. What do i need to do to signal that this is a binary file? And separately, is my Content-Disposition thing the right way of handlign the filename? Thanks. Jen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/