Inserting a blob

This is a discussion on Inserting a blob within the MySQL Database forums, part of the Database Forums category; Hi guys, I'm looking to insert a file, which was uploaded from a web form into a MySQL BLOB ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-15-2007
sophie_newbie
 
Posts: n/a
Default Inserting a blob

Hi guys, I'm looking to insert a file, which was uploaded from a web
form into a MySQL BLOB attribute in a database. The thing is I want to
be able to do it without first having to write the file to disk. What
I'm saying is that I don't want to use "INSERT INTO database (file)
values ('/uploaddir/file.dat')"

I know there must be another way of doing this because when I insert
data as a BLOB in PhpMyAdmin, I see that it doesn't insert a file
reference, rather a big long string that always starts with something
like "0x1f7645.....". I'd like to know what this string means and how
I can go about converting the uploaded files which are stored in
memory to a string like this and attatch them to the database without
having to write them to disk. The files are quite large so I want to
avoid doing this.

Thanks!

Reply With Quote
  #2 (permalink)  
Old 10-15-2007
Good Man
 
Posts: n/a
Default Re: Inserting a blob

sophie_newbie <paulgeeleher@gmail.com> wrote in
news:1192465740.221446.199280@v23g2000prn.googlegr oups.com:

> Hi guys, I'm looking to insert a file, which was uploaded from a web
> form into a MySQL BLOB attribute in a database. The thing is I want to
> be able to do it without first having to write the file to disk. What
> I'm saying is that I don't want to use "INSERT INTO database (file)
> values ('/uploaddir/file.dat')"
>
> I know there must be another way of doing this because when I insert
> data as a BLOB in PhpMyAdmin, I see that it doesn't insert a file
> reference, rather a big long string that always starts with something
> like "0x1f7645.....". I'd like to know what this string means and how
> I can go about converting the uploaded files which are stored in
> memory to a string like this and attatch them to the database without
> having to write them to disk. The files are quite large so I want to
> avoid doing this.
>
> Thanks!
>
>


I don't quite follow your question. The file has to be stored
*somewhere* - either in the regular OS file system, or in the database.

From your first paragraph, it seems like you don't want the file saved
on your system, but just in your database.

From your second paragraph, it seems like you want to store the file on
disk somewhere but just reference it's path in the database.

The value of your BLOB column ("0x1f7645...") is unprocessed binary data
- your actual image/file.

If you want to store just the path, change the column type to VARCHAR
and just store the final path to the file there.

Otherwise, restate your question?

Reply With Quote
  #3 (permalink)  
Old 10-15-2007
lark
 
Posts: n/a
Default Re: Inserting a blob

== Quote from sophie_newbie (paulgeeleher@gmail.com)'s article
> Hi guys, I'm looking to insert a file, which was uploaded from a web
> form into a MySQL BLOB attribute in a database. The thing is I want to
> be able to do it without first having to write the file to disk. What
> I'm saying is that I don't want to use "INSERT INTO database (file)
> values ('/uploaddir/file.dat')"
> I know there must be another way of doing this because when I insert
> data as a BLOB in PhpMyAdmin, I see that it doesn't insert a file
> reference, rather a big long string that always starts with something
> like "0x1f7645.....". I'd like to know what this string means and how
> I can go about converting the uploaded files which are stored in
> memory to a string like this and attatch them to the database without
> having to write them to disk. The files are quite large so I want to
> avoid doing this.
> Thanks!



i think what you see in phpMyAdmin is a handle to a temporary file. the file has
to be written to disk, i believe before being inserted into the database. you can
also implement a way of writing to a temporary location and then insert to
database. Finally, you'd delete the file from disk.

--
POST BY: lark with PHP News Reader
Reply With Quote
  #4 (permalink)  
Old 10-15-2007
Paul Lautman
 
Posts: n/a
Default Re: Inserting a blob

lark wrote:
> == Quote from sophie_newbie (paulgeeleher@gmail.com)'s article
>> Hi guys, I'm looking to insert a file, which was uploaded from a web
>> form into a MySQL BLOB attribute in a database. The thing is I want
>> to be able to do it without first having to write the file to disk.
>> What I'm saying is that I don't want to use "INSERT INTO database
>> (file) values ('/uploaddir/file.dat')"
>> I know there must be another way of doing this because when I insert
>> data as a BLOB in PhpMyAdmin, I see that it doesn't insert a file
>> reference, rather a big long string that always starts with something
>> like "0x1f7645.....". I'd like to know what this string means and how
>> I can go about converting the uploaded files which are stored in
>> memory to a string like this and attatch them to the database without
>> having to write them to disk. The files are quite large so I want to
>> avoid doing this.
>> Thanks!

>
>
> i think what you see in phpMyAdmin is a handle to a temporary file.
> the file has to be written to disk, i believe before being inserted
> into the database. you can also implement a way of writing to a
> temporary location and then insert to database. Finally, you'd delete
> the file from disk.


No, what you see in phpMyAdmin is a hexadecimal representation of the file
contents.
See http://dev.mysql.com/doc/refman/5.0/...al-values.html


Reply With Quote
  #5 (permalink)  
Old 10-15-2007
Kees Nuyt
 
Posts: n/a
Default Re: Inserting a blob

On Mon, 15 Oct 2007 09:29:00 -0700, sophie_newbie
<paulgeeleher@gmail.com> wrote:

>Hi guys, I'm looking to insert a file, which was uploaded from a web
>form into a MySQL BLOB attribute in a database. The thing is I want to
>be able to do it without first having to write the file to disk.


The form upload will write it to disk, if you like it or
not. That's just part of the HTTP protocol. When your CGI
or PHP script starts, the upload is already done, and the
file is in the configured upload directory.
You can then proceed to load the file in the BLOB column,
and delete the uploaded file from the upload directory.

HTH
Regards,
--
( Kees
)
c[_] Giving power and money to government is like giving
whiskey and car-keys to teenage boys. (PJ O'Rourke) (#291)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0