【Azure 应用服务】Storage Queue触发Azure Function时报错 The input is not a valid Base-64 string
2022-03-01 17:36
961 查看
问题描述
创建一个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
相关文章推荐
- Object-C学习之旅(一)----纠错篇---the running destination my Mac 64-bit is not valid for running the scheme
- The run destination My Mac 64-bit is not valid for Running the scheme
- The run destination My Mac 64-bit is not valid for Running the scheme
- 安装vmware-tools遇The path "" is not a valid path to the 3.8.13-44.1.1.el6uek.x86_64 kernel问题解决
- Ubuntu 16.04使用NASM编译时用ld链接程序出现:i386 架构于输入文件 sandbox.o 与 i386:x86-64 输出不兼容(I386 architecture in the input file sandbox.o is not compatible with i386: x86-64 output)
- vmware + centos 7安装vmtools时提示The path "" is not a valid path to the 3.10.0-327.el7.x86_64 kernel h
- 解决问题:The run destination My Mac 64-bit is not valid for Running the scheme
- 【Azure 应用服务】App Service服务无法启动,打开Kudu站点,App Service Editor 页面均抛出:The service is unavailable
- The run destination My Mac 64-bit is not valid for Running the scheme '*'.
- 【iOS】The run destination My Mac 64-bit is not valid for Running the scheme '*'
- VMware安装VMware tool是 遇到The path "" is not a valid path to the 3.10.0-693.el7.x86_64 kernel headers.
- The path "" is not a valid path to the 3.10.0-229.4.2.el7.x86_64 kernel headers.
- The input character is not valid in MATLAB statements or expressions.
- newStringUTF出现input is not valid Modified UTF-8错误解决办法
- VMware12 CentOS7:The path "" is not a valid path to the 3.10.0-514.el7.x86_64 kernel headers
- 启动服务,解决 the BASEDIRenvironmentvariable is not defined correctly
- JNI WARNING: NewStringUTF input is not valid Modified UTF-8: illegal start byte 0xb0
- The run destination My Mac 64-bit is not valid for Running the scheme '*'
- 编译错误“The run destination My Mac 64-bit is not valid for Running the scheme '***',解决办法
- The run destination My Mac 64-bit is not valid for Running the scheme