将文件插入 mysql Blob

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9109112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 11:59:13  来源:igfitidea点击:

Insert file into mysql Blob

mysql

提问by Flex60460

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

我尝试在 blob 字段上插入 Open Office 文档。为此,我尝试

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.

这在 Windows 上运行良好,但在 Mac Os 上,文件不会加载到 docFile 字段。

Is anyone has experience about that?

有没有人有这方面的经验?

Thanks

谢谢

回答by srikanthvarma

File.separatoris 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 /.

File.separator是任一/\所使用的路径分割到一个特定的文件。例如在 Windows 上它是\C:\Documents\Test。但在 Mac 上它是/.

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

所以使用File.separator而不是/or \,那么它将适用于 Mac 和 Windows。

You can Update the column value having type 'blob'

您可以更新类型为“blob”的列值

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