cancel
Showing results for 
Search instead for 
Did you mean: 

Save image as blob form file path

Former Member
8,146

i have table with 2 column ID , Image(save file path) but i need save image as Blob in new column. i am using SQLAnywhere 12.0.1.3873

Accepted Solutions (0)

Answers (3)

Answers (3)

Breck_Carter
Participant

If the file exists on the same computer that is running the SQL Anywhere 12 engine, then see xp_read_file system procedure.

If the file exists on a different computer (say, on a client computer that is connected over the network to dbsrv12.exe running on a server computer) then see READ_CLIENT_FILE function.

VolkerBarth
Contributor
0 Kudos

If I understand your situation correctly, you have already a list of image file pathes in the according table but want to store the actual images there, too. So you will need to use xp_write_file() to read the file contents. (Note: That would require the database engine can access these files, i.e. they are not stored on a client computer.)

Here's a good starting point from the docs:

Insertion of documents and images

To go on further, you might use a cursor to loop over each row from the table and access the according file and insert its data via an UPDATE statement. There are also ways to do to this in one UPDATE statement, such as

UPDATE MyTable SET MyImage = xp_read_file(MyImagePath);


However, that may be a heavy burden in case you have lots of images to store, so a one-by-one approach might be easier.

Former Member
0 Kudos

i will try to use xp_read_file as "update test set blob=xp_read_file( image);"

VolkerBarth
Contributor
0 Kudos

OK, you have been faster:)

Former Member
0 Kudos

done using xp_read_file ,but now i have other problem ,there are image too large and i need to reduce its size before save it as blob.

VolkerBarth
Contributor
0 Kudos

image too large

Too large for what? What datatype has the according column?

Former Member
0 Kudos

some image file with size 3 ,4 MB and i need to reduce its size before save in database for performance

VolkerBarth
Contributor
0 Kudos

Hm, then you might read that article on what SQL Anywhere can - and cannot - do to compress data:

Compressed Columns - where's the squeeze - client or server?

Breck_Carter
Participant
0 Kudos

What kind of files are they? JPGs are already compressed so you won't be able to do much. BMPs will benefit greatly from compression, so will PNGs but to a lesser extent.

SQL Anywhere splits blob data into separate storage so it does a pretty efficient job of handling them... don't assume they will cause a performance problem, do some testing to prove it.

Are you using MobiLink synchronization? If so, there are techniques that can be used so blobs don't kill sync times.