输入不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符或非法字符
因此,我有一个 azure 函数,它在将对象放入 azure 队列之前以 Base64 对其进行编码,然后在下一个函数中对对象进行解码和反序列化。 编码和发送它的代码在这里:
var trackIdAndUserid = new TrackIdAndUserId { TrackId = track.Track.Id, UserId = track.UserId };
var message = JsonConvert.SerializeObject(trackIdAndUserid);
buffer = Encoding.Unicode.GetBytes(message);
string msg = Convert.ToBase64String(buffer);
await queueClient.SendMessageAsync(msg);
队列上的示例消息是
ewAiAFQAcgBhAGMAawBJAGQAIgA6ACIAMABpADQAbgBIAGEANwB3AEwAQwBYADEAMQBNADcAeQBJAHAANwBpAFQASgAiACwAIgBVAHMAZQByAEkAZAAiADoAIgAzADgAMAA5AGYANQBjADMALQA4ADEANABmAC0ANABmADYAYwAtAGIAYwAzAGMALQBhAGYANgA3AGYANAAwAGQAMwBlADMAZgAiAH0A
解码它的代码在这里:
byte[] buffer = Convert.FromBase64String(myQueueItemStringBase64);
string myQueueItemString = Encoding.Unicode.GetString(buffer);
var myQueueItem = JsonConvert.DeserializeObject<TrackIdAndUserId>(myQueueItemString);
So I have an azure function that encodes an object in Base64 before putting it on an azure queue and then the object is decoded and deserilized in the next function.
The code for encoding it and sending it is here:
var trackIdAndUserid = new TrackIdAndUserId { TrackId = track.Track.Id, UserId = track.UserId };
var message = JsonConvert.SerializeObject(trackIdAndUserid);
buffer = Encoding.Unicode.GetBytes(message);
string msg = Convert.ToBase64String(buffer);
await queueClient.SendMessageAsync(msg);
An example message on the queue is
ewAiAFQAcgBhAGMAawBJAGQAIgA6ACIAMABpADQAbgBIAGEANwB3AEwAQwBYADEAMQBNADcAeQBJAHAANwBpAFQASgAiACwAIgBVAHMAZQByAEkAZAAiADoAIgAzADgAMAA5AGYANQBjADMALQA4ADEANABmAC0ANABmADYAYwAtAGIAYwAzAGMALQBhAGYANgA3AGYANAAwAGQAMwBlADMAZgAiAH0A
The code to decode it is here:
byte[] buffer = Convert.FromBase64String(myQueueItemStringBase64);
string myQueueItemString = Encoding.Unicode.GetString(buffer);
var myQueueItem = JsonConvert.DeserializeObject<TrackIdAndUserId>(myQueueItemString);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过添加队列客户端选项并将选项中的编码设置为 base64 来修复它
I fixed it by adding a queue client options and setting the encoding in the options to base64