Mailing List Archive

File Uploads / Mime Types
Hey everyone,

I'm working on serveral Embperl scripts that insert and retrive Binary Large
Objects (BLOBs) into/from an Oracle database using DBI.

I'm currently getting the object (in this case an image) with code like this:

my $buffer;
my $data;
($data .= $buffer) while read ($fdat{image}, $buffer, 32768 * 2);

Cgi.pm has a method for figuring out the MIME type of the upload, like this:

$uploadfile = $query->param("upload");
$mime_type = uploadInfo($file)->{'Content-Type'};

Is there a way of doing this with Embperl? If so, that would be great... It
would be silly to have to a) ask the user for the type or b) use CGI.pm beside
Embperl just to get that mime type...

Btw, it's a lot of fun figuring out how to insert binary date from a form to a
database... the man pages, etc for DBI on this aren't too clear. I got it
eventually though.

What's the biggest upload that Embperl can handle? Would it be feasible to
upload 400MB movie clips or such through Embperl to a database? Or what the
webserver run out of memory and die miserably?

When using

$sth->bind_param(1, $data, {ora_type=>113}),

Is there a way to buffer the moving of data between the user's browser and the
database so that it doesn't load a 400MB file into memory?

Thanks everyone,

Wim Kerkhoff, Software Engineer
NetMaster Networking Solutions
wim@netmaster.com
RE: File Uploads / Mime Types [ In reply to ]
> $uploadfile = $query->param("upload");
> $mime_type = uploadInfo($file)->{'Content-Type'};
>
> Is there a way of doing this with Embperl?

From the docs:

When you have installed CGI.pm 2.46 or above you may also retrieve the
filename (local filename, as it was on the browser side) and the
informations provied by the CGI.pm uploadInfo function. To get the filename
just print out the value of the correspondig %fdat entry, instead of using
it as a filehandle. To get the uploadInfo use the fieldname with a dash in
front of it:


Example:


# ImageName is the NAME of the field, you must replace it with whatever
# name is given in your HTML code
Filename: [+ $fdat{ImageName} +] <br>
Content-Type: [+ $fdat{-ImageName} -> {'Content-Type'} +] <br>


>
> What's the biggest upload that Embperl can handle? Would it be
> feasible to
> upload 400MB movie clips or such through Embperl to a database?
> Or what the
> webserver run out of memory and die miserably?
>

file uploads are the only thing that Embperl uses CGI.pm. CGI.pm reads the
data in small chunks and writes it to disk, so there is no problem with
memory, as far as you disk has enounght free space.

> When using
>
> $sth->bind_param(1, $data, {ora_type=>113}),
>
> Is there a way to buffer the moving of data between the user's
> browser and the
> database so that it doesn't load a 400MB file into memory?
>

I thought there is some way, but I can't find it. I think you should search
the DBI users mailinglist archiv for that problem.

Gerald
RE: File Uploads / Mime Types [ In reply to ]
Thanks Gerald.

Now that I seen it again, I remember seeing it at one point in the docs when I
was looking for something else, but when I needed it I couldn't find it of
course :(

On 27-Apr-2000 Gerald Richter wrote:
>> $uploadfile = $query->param("upload");
>> $mime_type = uploadInfo($file)->{'Content-Type'};
>>
>> Is there a way of doing this with Embperl?
>
>>From the docs:
>
> Content-Type: [+ $fdat{-ImageName} -> {'Content-Type'} +] <br>

> file uploads are the only thing that Embperl uses CGI.pm. CGI.pm reads the
> data in small chunks and writes it to disk, so there is no problem with
> memory, as far as you disk has enounght free space.

Ok.

Regards,

Wim Kerkhoff, Software Engineer
NetMaster Networking Solutions
wim@netmaster.com