Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将图像文件保存到Rails中的数据库_Ruby On Rails_Ruby_Image_Binary - Fatal编程技术网

Ruby on rails 将图像文件保存到Rails中的数据库

Ruby on rails 将图像文件保存到Rails中的数据库,ruby-on-rails,ruby,image,binary,Ruby On Rails,Ruby,Image,Binary,我需要将图像从文件保存到PostgreSQL数据库作为二进制文件。试着这样做: image_file = File.open("image.png", "rb") { |file| file.read } Image.create(product_id: product_id, image: image_file) 此代码给出了以下错误: string contains null byte 使用回形针或类似工具,或将二进制文件转换为base64都不是一个选项。如果可以,请尝试向我们提供更多信

我需要将图像从文件保存到PostgreSQL数据库作为二进制文件。试着这样做:

image_file = File.open("image.png", "rb") { |file| file.read }
Image.create(product_id: product_id, image: image_file)
此代码给出了以下错误:

string contains null byte

使用回形针或类似工具,或将二进制文件转换为base64都不是一个选项。

如果可以,请尝试向我们提供更多信息。我知道最近有一个关于Rails的PR,修复了PostgreSQL中更多多余的bytea逃逸。所以一定要尝试更新你的系统,看看这是否有帮助。如果没有,请提供更多信息,如果你能


数据库中列的类型是什么?检查此链接:二进制。更改列类型也不是选项哪一行失败?读取文件还是将其保存到数据库中?