Hi I was trying to send the decoded base64(binary) value to sql update query as varbinary(max)
I can able to generate the pdf, by decoding the base64 using atob(base64)
.
I tried many ways to pass the binary value to sql query as varbinary(max). please check my sample queries and error messages:
let qry = `update ${tableName} set PrintableReport = CONVERT(varbinary(MAX),'${printableReport}') where TransactionId = '${transactionId}'`
// ERROR: "message":"'ðÊ\u0016¼«þWÚC>\u0001õ³àÌ¥Îqq(&¢©\r\u0016*\u001bê䪰Á0'Ljï.\u001c»@t·$ë. ' is an invalid name because it contains a NULL character or an invalid unicode character."
let qry = `update ${tableName} set PrintableReport = (select * from OPENROWSET(BULK '${filePath}', SINGLE_BLOB) as varbinary(MAX)) where TransactionId = '${transactionId}'`
let qry = `update ${tableName} set PrintableReport = (SELECT CAST(bulkcolumn AS VARBINARY(MAX)) FROM OPENROWSET(BULK '${filePath}',SINGLE_BLOB) AS x) where TransactionId = '${transactionId}'`
let qry = `DECLARE @pdf VARBINARY(MAX) SELECT @pdf = BulkColumn FROM OPENROWSET(BULK N'${filePath}', SINGLE_BLOB) AS Document; SELECT @pdf, DATALENGTH(@pdf) update ${tableName} set PrintableReport = (@pdf) where TransactionId = '${transactionId}'`
// ERROR: "message":"Cannot bulk load because the file \"C:\\projects\result_binary.pdf\" could not be opened. Operating system error code (null)."
Please suggest me the right way to acheive this. Solutinos will be appriciated. Thanks in advance