如何将byte []转换为base64Binary(不是base64String)? [英] How to convert byte[] to base64Binary (not base64String)?

查看:106
本文介绍了如何将byte []转换为base64Binary(不是base64String)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server表列类型为Image。

The SQL server table column type is Image.

C#代码将文件(例如.docx)转换为byte []。 byte []可以插入SQL中的Image列。但客户端需要base64Binary转换回文件。他们收到错误"i s
不是"base64Binary
"的有效值和" Base-64字符数组的长度无效 " ;.如何将byte []转换为  base64Binary?

The C# code converts a file (e.g. .docx) to byte[]. The byte[] can be insert into the the Image column in SQL. But the client required base64Binary to convert back to a file. They received an error "is not a valid value for 'base64Binary" and "Invalid length for a Base-64 char array". How can I convert the byte[] to base64Binary?

我试过base64String。我得到"nvarchar与图像不兼容"。我谷歌但它似乎只找到转换为base64String。

I tried base64String. I got "nvarchar is incompatible with image". I google it but it seems only finding convert to base64String.

谢谢。

推荐答案

我认为你应该使用
Convert.ToBase64String 而不是将数据插入数据库,而是在将字符串发送到客户端之前将提取的字节转换为base-64字符串。客户将使用
Convert.From64String

I think that you should use Convert.ToBase64String not for inserting the data to database, but for converting the extracted bytes to base-64 string before sending the string to Clients. The Clients will use Convert.From64String.

显示有关数据和错误的详细信息。哪些字符串发送给客户?


这篇关于如何将byte []转换为base64Binary(不是base64String)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆