Azure Functions: Queue Trigger is expecting Base-64 messages and doesn't process them correctly
Use Azure.Storage.Queues
nuget package and use the following code to convert string to Base 64 encode. You need to encode using Encoding.UTF8.GetBytes (plainText).
await queueClient.SendMessageAsync(Base64Encode(serializedCommand), cancellationToken);
private static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
For more details, you could refer to this issue.
As an alternative, you can take advantage of the built in functionality for converting the message to Base64 by creating the client with an QueueClientOptions
with MessageEncoding
set to QueueMessageEncoding.Base64
.
For example:
_queue = new QueueClient(connectionString, queueName, new QueueClientOptions
{
MessageEncoding = QueueMessageEncoding.Base64
});
...
var message = "some message";
await _queue.SendMessageAsync(message); // Will be converted as Base64.