c# - base64 编码 HttpPostedFileBase

标签 c# json asp.net-mvc web-services http

我想用 base64 对接收到的图像进行编码 HttpPostedFileBase 以将其发送到 json 对象中,但我不知道该怎么做。 .请告诉我如何将它解码回 HttpPostedFileBase

最佳答案

我试过了,成功了

string theFileName = Path.GetFileName(YourFile.FileName);
byte[] thePictureAsBytes = new byte[YourFile.ContentLength];
using (BinaryReader theReader = new BinaryReader(YourFile.InputStream))
{
    thePictureAsBytes = theReader.ReadBytes(YourFile.ContentLength);
}
string thePictureDataAsString = Convert.ToBase64String(thePictureAsBytes);

关于c# - base64 编码 HttpPostedFileBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31313280/

相关文章:

c# - 方法重载决议系统如何决定在传递空值时调用哪个方法?

c# - 添加 Azure AD 身份验证时出现 CORS 错误

c# - 我可以将 json 解析为字符串或其他具体类型作为对象吗?

javascript - 使单个页面的浏览器缓存无效

asp.net-mvc - 如何在使用Jquery UI选项卡和Custom Error处理程序时捕获Ajax错误

c# - Reflection.Emit 泛型基类泛型方法调用

c# - 获取包含可观察属性的对象列表的单个可观察值?

PHP IF 如何包含多个条件?

java - Jackson json 映射器

javascript - 以编程方式禁用 jquery ui 对话框上的按钮,直到 ajax 调用完成?