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" <[email protected]>
> 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 
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




      

_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to