Flex60460
Flex60460

Reputation: 993

Insert file into mysql Blob

I try to insert a Open Office document on a blob field. To do this I try

INSERT INTO my_table (stamp, docFile) VALUES (NOW(), LOAD_FILE('/tmp/my_file.odt'));

This works well on windows but on Mac Os the file isn't load on docFile field.

Is anyone has experience about that?

Thanks

Upvotes: 9

Views: 33890

Answers (1)

srikanthvarma
srikanthvarma

Reputation: 11

File.separator is either / or \ that is used to split up the path to a specific file. For example on Windows it is \ or C:\Documents\Test. But on Mac it is /.

So use File.separator instead of / or \, then it will work for both Mac and Windows.

You can Update the column value having type 'blob'

UPDATE `TableName` SET `ColumnName`=LOAD_FILE('FilePath/FileName.bin') WHERE `YourCondition` 
// FilePath -> C:/foldername/filename.bin

Upvotes: 1

Related Questions