[Catalyst] PDF upload problems (prob OT)?

Dr. Jennifer Nussbaum bg271828 at yahoo.com
Thu Nov 27 12:51:38 GMT 2008


Hi. Following up here after some time on another project.

--- On Fri, 11/7/08, Joel Bernstein <joel at fysh.org> wrote:

> From: Joel Bernstein <joel at fysh.org>
> Subject: Re: [Catalyst] PDF upload problems (prob OT)?
> To: "The elegant MVC web framework" <catalyst at lists.scsys.co.uk>
> Date: Friday, November 7, 2008, 5:01 PM
> 2008/11/8 Dermot <paikkos at googlemail.com>
> 
> > 2008/11/7 Dr. Jennifer Nussbaum
> <bg271828 at yahoo.com>:
> > > 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 93333 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




      



More information about the Catalyst mailing list