【发布时间】:2019-11-18 16:19:20
【问题描述】:
我有一个 base64 jpeg,如下所示:data:image/jpeg;base64,我正在尝试将其转换为 MemoryStream,以便将其上传到 OneDrive....这是我目前得到的:
byte[] frontBytes = Convert.FromBase64String(user.FrontLicense);
using (MemoryStream frontMS = new MemoryStream(frontBytes))
{
await graphClient.Me.Drive.Items[newFolder.Id].ItemWithPath("FrontLicense.jpeg").Content.Request().PutAsync<DriveItem>(frontMS);
}
但我收到此错误:
输入不是有效的 Base-64 字符串,因为它包含非 base-64 字符、两个以上的填充字符或非法字符 在填充字符之间。
在这一行:
byte[] frontBytes = Convert.FromBase64String(user.FrontLicense);
这就是 user.FrontLicense 的样子:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoM.....
我做错了什么?
【问题讨论】:
-
你需要在base64解码之前删除
data:image/jpeg;base64,。 -
看起来这可能是重复的...check out this question
-
@JEllery:不是那个副本。
标签: c# asp.net memorystream