Home > front end >  The input is not a valid Base-64 string as it contains a non-base 64 character, more than two paddin
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two paddin

Time:03-28

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);

CodePudding user response:

I fixed it by adding a queue client options and setting the encoding in the options to base64

var queueClient = new QueueClient(configuration["AzureWebJobsStorage"], "add-track-to-cosmos", new QueueClientOptions { MessageEncoding = QueueMessageEncoding.Base64});

CodePudding user response:

I have stumbled across this as we have the same problem since updating to the Azure.Storage.Queues package now none of our queue triggered message handlers are functioning, reporting the same error message you have documented.

We don't convert our messages from JSON format to base64, why would you do this?

I have tried adding to our message sending but we still get the same error: -

var options = new QueueClientOptions { MessageEncoding = QueueMessageEncoding.None };

So I can see the messages being moved to the poison queue and they all look visually as I would expect, but not in Base64, should they be?

  • Related