c#-base64 jpeg to MemoryStream?

问题描述 投票:0回答:1

我有一个像这样的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 jpeg:data:image / jpeg; base64,我正在尝试将其转换为MemoryStream,以便可以将其上传到OneDrive。...到此为止,我得到了:byte [] frontBytes =转换。...

c# asp.net memorystream
1个回答
0
投票

开头的部分-data:image/jpeg;base64,-不是base64数据的一部分。因此,您需要先删除它:

© www.soinside.com 2019 - 2024. All rights reserved.