如何将 Base64 转换为字符数组 - C# - Microsoft Graph?
我的代码接收 Base64 值作为字符串(公共字符串 Base64Foto)。 我必须获取该值并将其转换为 Char[] 以将其发送到 Microsoft 图。
private static async Task<bool> EnviarMicrosoft(DadosApData dadosApData)
{
try
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "tenantID";
var clientId = "clientID";
var clientSecret = "clientSecret";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var bytes = Convert.FromBase64String(dadosApData.Base64Foto);
var charFromByte = System.Text.Encoding.UTF8.GetString(bytes).ToCharArray();
using var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(charFromByte));
await graphClient.Users[dadosApData.Email].Photo.Content.Request().PutAsync(stream);
return true;
}
catch (Exception ex)
{
LambdaLogger.Log(ex.Message);
throw ex;
}
}
当我在 Postman 中执行此操作时,它正常工作(作为二进制文件),但是当我尝试将其传递给代码时,它不起作用,我的转换是否错误?
PS:我收到错误:Microsoft.Fast.Profile.Core.Exception.ImageNotFoundException
My code receives a Base64 value as a String (Public String Base64Foto).
I must take this value and convert it to Char[] to send it to graph Microsoft.
private static async Task<bool> EnviarMicrosoft(DadosApData dadosApData)
{
try
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "tenantID";
var clientId = "clientID";
var clientSecret = "clientSecret";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var bytes = Convert.FromBase64String(dadosApData.Base64Foto);
var charFromByte = System.Text.Encoding.UTF8.GetString(bytes).ToCharArray();
using var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(charFromByte));
await graphClient.Users[dadosApData.Email].Photo.Content.Request().PutAsync(stream);
return true;
}
catch (Exception ex)
{
LambdaLogger.Log(ex.Message);
throw ex;
}
}
When I do this in Postman, it works normally (as a binary), but when I try to pass this to the code, it doesn't work, is my conversion wrong?
PS: I'm Receving the error: Microsoft.Fast.Profile.Core.Exception.ImageNotFoundException
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的代码,它可以更新用户照片:
控制器:
cshtml:
This is my code and it can update the user photo:
Controller:
cshtml: