【Azure 应用服务】Storage Queue触发Azure Function时报错 The input is not a valid Base-64 string

简介: 【Azure 应用服务】Storage Queue触发Azure Function时报错 The input is not a valid Base-64 string

问题描述

创建一个PowerShell脚本的Azure Function,触发方式为 Storage Queue。但执行函数结果一直失败 (Failed).

错误消息为:

Executed 'Functions.QueueTrigger1' (Failed, Id=..., Duration=30ms) The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Funciton 代码:

# Input bindings are passed in via param block.
param([string] $QueueItem, $TriggerMetadata)
# Write out the queue message and metadata to the information log.
Write-Host "PowerShell queue trigger function processed work item: $QueueItem"
Write-Host "Queue item expiration time: $($TriggerMetadata.ExpirationTime)"
Write-Host "Queue item insertion time: $($TriggerMetadata.InsertionTime)"
Write-Host "Queue item next visible time: $($TriggerMetadata.NextVisibleTime)"
Write-Host "ID: $($TriggerMetadata.Id)"
Write-Host "Pop receipt: $($TriggerMetadata.PopReceipt)"
Write-Host "Dequeue count: $($TriggerMetadata.DequeueCount)"

 

通过向Storage Queue中添加消息时候触发:

az storage message put --content "This is a function test message"

 

问题分析

根据错误消息,Function (Storage Queue)触发的消息需要 Base64编码,如发送 "This is a function test message"  这段消息,需要在发送消息时候转换为base64编码。

 

在CMD中调用PowerShell进行类型转换:

powershell "[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"This is a function test message\"))"

在Powershell中直接转换:

[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("This is a function test message"))

所以,修改后的向Storage Queue中添加消息的命令为:

$queuemsg = [convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("This is a function test message"))


az storage message put --content $queuemsg

 

参考资料

适用于 Azure Functions 的 Azure 队列存储触发器: https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-storage-queue-trigger?tabs=powershell#encoding

 

相关文章
|
24天前
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
|
24天前
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
|
24天前
|
缓存
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
|
24天前
|
Python
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
|
24天前
|
C#
【Azure Function】Function App启动时出现 Failed to open local port 4001 错误,这是什么情况呢?
【Azure Function】Function App启动时出现 Failed to open local port 4001 错误,这是什么情况呢?
|
24天前
|
C# C++
【Azure Function】在VS Code中创建Function项目遇见 No .NET worker runtimes found
【Azure Function】在VS Code中创建Function项目遇见 No .NET worker runtimes found
|
24天前
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中
|
24天前
|
API C++ Python
【Azure Function】示例运行 python durable function(model V2)
【Azure Function】示例运行 python durable function(model V2)
|
24天前
|
C++
【Azure Function App】在VS Code中,创建好Function App后部署到Azure中,无法选择Subscriptions
【Azure Function App】在VS Code中,创建好Function App后部署到Azure中,无法选择Subscriptions
|
24天前
|
安全 Oracle Java
【Azure Function】Azure Function中使用 Java 8 的安全性问题
【Azure Function】Azure Function中使用 Java 8 的安全性问题