2

I need to save image from file to PostgreSQL database as binary. Trying to do it like this:

image_file = File.open("image.png", "rb") { |file| file.read }
Image.create(product_id: product_id, image: image_file)

This code gives me the following error:

string contains null byte

Using paperclip or similar, or converting binary to base64 are not an option.

1 Answers1

0

Try providing us more information, if you're able. I know there was a recent PR for Rails that fixed more superfluous bytea escaping in PostgreSQL. So definitely try updating your system to see if that helps. If it doesn't, please provide us more information if you're able.

Here's a link to the PR

Collin Graves
  • 2,207
  • 15
  • 11