reading a binary file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

I am trying to store dll file uploaded by user to DB. But I am seeing
issues, dll file is getting corrupted. The size of the file inserted
is greater than original file. Can some body help me here. Posting cgi-
perl code snippet,

<form method=post ENCTYPE="multipart/form-data">
<input type=hidden name=type value="application/octet-stream">
<b>Path to file:</b><br>
<input type=file name=data id=data size=60><br><br>

<input name=description size=60><br><br>
<input type=submit value="Submit">

#perl-cgi code,executed on Linux box
#this gives me file handle
my $daata=$cgi->upload('data');
my $fulldata;

#reading content of binary file
read($daata, $fulldata, -s $daata );

$dbh->do("insert into attachments"
        . " ( file_name,file_data)"
            . " values"
            . "(?,?)",undef, $file_name, $fulldata);
# . "(?,?)",undef, $file_name, $dbh->BLOB_TYPE($fulldata)); this also
doesn't work

But the dll is getting corrupted. The attachments.file_data field is
of type longblob. Am I doing something wrong here? Is there any issue
with the statement that reads content of the file?

Please help me on this,

Re: reading a binary file

Rahul!! wrote as on 21. Jun 2011:
Quoted text here. Click to load it

Is the size already larger in the memory image of the file ($fulldata),
or does the problem really occur on inserting the file into the
database? In the latter case, it might help either asking in a newsgroup
dedicated to your database, or at least mention what database you are


Posted via /

Re: reading a binary file


Quoted text here. Click to load it

Why don't you test this by writing to a local file instead of inserting
it into a database.

Are you absolutely sure your reading a binary file.
The database BLOB is an after thought.

Haven't you ever been so frustrated you would try anything to get
to the root problem?

Start chopping at the base, then work yourself up. Eventually,
when you find out where in the chain the problem is, a feeling
of satisfaction will boost your self-esteem.

When you have to work to solve a problem, its much more satisfying
when you do.


Site Timeline