Loading ...
Sorry, an error occurred while loading the content.

582RE: Uploading files

Expand Messages
  • Tim Moore
    Jul 12, 2002
    • 0 Attachment
      > -----Original Message-----
      > From: Tim Moore
      > Sent: 12 July 2002 11:15
      > To: 'Quentin Smith'
      > Cc: asp@...
      > Subject: RE: Uploading files
      >
      >
      > > -----Original Message-----
      > > From: Quentin Smith [mailto:quentins@...]
      > > Sent: 11 July 2002 20:07
      > > To: Tim Moore
      > > Cc: asp@...
      > > Subject: Re: Uploading files
      > >
      > >
      > >
      > > I believe was is happening is this:
      > > Each time you call read(), it fetches up to 1024 bytes (1kb, as you
      > > set). Since each time read is called, it erases $PostedData
      > and then
      > > writes up to 1024 bytes into it, you can only end up with the
      > > last 1024
      > > bytes. HOWEVER, the last time read is called, it reaches
      > EOF, so the
      > > last thing $PostedData is set to is undef. Here is a modified
      > > version of
      > > the code that I think will work (untested):
      > >
      > > my $length = $Request->{TotalBytes};
      > > print "TotalBytes = " . $length . "<br>";
      > >
      > > my $fileup = $Request->{FileUpload}{uploadedfile};
      > > my $filehandle = $fileup->{FileHandle};
      > > my $PostedData = "";
      > > print "PostedData = " . $PostedData . "<br>";
      > > print "Length = " . length($PostedData) . "<br>";
      > > my $in_buffer;
      > > while (read($filehandle, $in_buffer, 1024))
      > > {
      > > print "a";
      > > $PostedData .= $in_buffer; # Equivalent to
      > > $PostedData =
      > > $PostedData . $in_buffer, except .= is shorter and faster.
      > > # data from the uploaded file read into $PostedData
      > > }
      > >
      > > my $ContentType = $fileup->{ContentType};
      > > print "ContentType = " . $ContentType . "<br>";
      > >
      > > print "PostedData = " . $PostedData . "<br>";
      > > print "Length = " . length($PostedData) . "<br>";
      > > # As always, watch for line breaks.
      > >
      > > __END__
      > >
      > > HTH,
      > > --Quentin
      >
      > Fantastic. That was the problem!
      >
      > I love it when the fix is so simple. It looks like I don't
      > need CGI in the end but then I guess it's because my form is
      > only posting the file so there's nothing to seperate? Seems
      > to work anyway I can upload a PDF and return it and just
      > tested it with BinaryWrite also and the PDF opens in Acrobat
      > Reader! Cool.
      >
      > Many thanks :-)
      >
      >
      > Tim.
      >

      Ah, I spoke to soon. It turns out the code that processes the data is
      expecting the full MIME multipart/form stuff (this is a port from an IIS
      app. It decodes the header internally in a bit of C++). So although I've got
      just the file itself, I need all the MIME header surrounding it.

      So I guess this is where CGI.pm comes in? Thing is though I don't want to
      use CGI to dynamically create the form or write to a temp file which is what
      the samples seem to do, I just want to get the full data with MIME headers
      (without CGI breaking it up for me).

      I've tried the equivalent of what we do in IIS which is...

      $Request->ServerVariables("CONTENT_TYPE");

      but this gives me a collection hash. If I add ->Item() onto the end I get
      something like this...

      multipart/form-data; boundary=---------------------------7d222cc5a02e4

      That's sort of along the lines but I think our code is expecting more than
      that. $fileup->{ContentType} gives me the content type (e.g.
      'application/pdf') but that's too little information it seems. Our C++ code
      is expecting a content type string with multipart/form and various things it
      can decode and then seems to be expecting the data itself to be wrapped up
      in MIME headers too (whereas I'm just getting the raw data).

      Hmm, any ideas? Anyway, looks like I'll have to get to grips with MIME a bit
      more (and our code).


      Cheers,

      Tim.

      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Show all 11 messages in this topic