0

What is the correct way to insert Buffer as BLOB just 1-to-1 without serializing to string/hex? Is it possible at all from Node.js?

At my backend I already have Buffers with binary data and want to store them with minimum overheads using prepared statements. I'm getting ER_TRUNCATED_WRONG_VALUE_FOR_FIELD errno:1366 Incorrect string value error. It looks like the library just assumes there is a valid utf8 string in a buffer.

Vasan
  • 4,810
  • 4
  • 20
  • 39
V.B.
  • 6,236
  • 1
  • 33
  • 56
  • @Vasan this is not a duplicate, I've seen the question, here I use mysql2 with prepared statements and the question is how to avoid turning buffers to hex strings before inserting to MySQL. – V.B. Apr 25 '18 at 19:53
  • Yes, hence why I retracted my flag and added the tag. – Vasan Apr 25 '18 at 19:54
  • After hours googling found a similar question but without an answer https://stackoverflow.com/questions/49933194/npm-mysql-sending-blob-data-to-a-mysql-server-as-a-binary-format – V.B. Apr 25 '18 at 20:22
  • By the way, how do you conclude **the library just assumes there is a valid utf8 string in a buffer** from that line? It just checks if the given value is a Buffer. – Vasan Apr 25 '18 at 21:11
  • Going forward and backward over callstack from this line. And I get an error from my tests, but it works fine with .toString() called on buffer. Haven't checked if it works correctly though. Also it is mentioned here at the bottom: https://github.com/sidorares/node-mysql2/blob/master/documentation/Prepared-Statements.md – V.B. Apr 25 '18 at 21:14

0 Answers0