Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Insert large binary file in database (MySQL)

Reply
Thread Tools

Insert large binary file in database (MySQL)

 
 
Alexey Petrushin
Guest
Posts: n/a
 
      06-11-2008
Hello!

Probably a stupid question ...
How can i insert large binary file in MySQL using IO stream?

For example, 'Sequel' can do 'insert' as:

dataset << {:name => 'a name', :value => 'some value'}

i need something like:

File.open('path_to_binary_file'){|file|
dataset << {:name => 'a name', :value => file}
}

Thanks!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Alexey Petrushin
Guest
Posts: n/a
 
      06-11-2008
In Java it can be done this way:

File file = new File("/home/sumedha/sumedha.jpg");
fis = new FileInputStream(file);
ps = conn.prepareStatement("insert into pictures(id, name,
photo) values (?, ?, ?)");
ps.setString(1, "001");
ps.setString(2, "sumedha");
ps.setBinaryStream(3, fis, (int) file.length());
ps.executeUpdate();
conn.commit();

hope Ruby also has something similar ...
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
David Masover
Guest
Posts: n/a
 
      06-12-2008
On Wednesday 11 June 2008 04:43:54 Alexey Petrushin wrote:
> Probably a stupid question ...
> How can i insert large binary file in MySQL using IO stream?


You probably shouldn't.

MySQL is for storing small things, like userids, (hashed) passwords, posts,
etc.

For larger things, it's going to be easier and more efficient to use the
filesystem.

 
Reply With Quote
 
alandacosta@gmail.com
Guest
Posts: n/a
 
      06-13-2008
You can create a text field in your table, and convert to/from Base64/
Binary as needed. You have to do a File.open, iterating each line, and
<< Base64.encode64(line), to encode ; Base64.decode64(line), to
decode. It's an option. I know BLOB sends, using the db adapter are a
problem with Postgres when the db is non-local (not on the same
machine) to the app. If you have to store the file object in your
database, I'd recommend the Base64 transform. Note: storage compared
to binary will increase slightly by converting to/from Base64 (even
though ruby is decently fast at this), application processing time
will go up due to conversions, and your DB machine may slow down
somewhat (dependent on load). If you do go this route, you should md5
or sha1 hash the binary object (before transform) to save on
redundantly storing objects, and rather use a join table for a user to
file association, against the md5/sha1.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
I saved password into the database with "binary" data type from GetByte method. How can I to compare the password that between database and transfered from the page? Benny Ng ASP .Net 3 01-25-2006 06:49 AM
insert binary that to access database jcharth@hotmail.com ASP .Net 0 01-06-2006 10:33 PM
Cannot insert Large text into Database Memo field Olaf Winterton ASP General 4 01-05-2004 06:09 PM



Advertisments