【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

 

相关文章
|
2月前
|
C#
【Azure Function】Function App出现System.IO.FileNotFoundException异常
Exception while executing function: xxxxxxx,The type initializer for 'xxxxxx.Storage.Adls2.StoreDataLakeGen2Reading' threw an exception. Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the
123 64
|
2月前
|
JSON C# 数据格式
【Azure Function】C#独立工作模式下参数类型 ServiceBusReceivedMessage 无法正常工作
Cannot convert input parameter 'message' to type 'Azure.Messaging.ServiceBus.ServiceBusReceivedMessage' from type 'System.String'.
121 73
|
1月前
|
JavaScript API
【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
Running your function in portal requires the app to explicitly accept requests from https://portal.azure.cn. This is known as cross-origin resource sharing (CORS).Configure CORS to add https://portal.azure.cn to allowed origins.
|
2月前
|
Java Windows
【Azure Function】部署Java Function失败:报错deploy [ERROR] Status code 401和警告 'China North 3' may not be a valid region
1:deploy [ERROR] Status code 401, (empty body). 2: China North 3 may not be a valid region,please refer to https://aka.ms/maven_function_configuration#supported-regions for values. 3:  <azure.functions.maven.plugin.version>1.36.0</azure.functions.maven.plugin.version>
54 11
|
5月前
|
Linux Python
【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend'
ERROR: Error: No module named '_cffi_backend', Cannot find module. Please check the requirements.txt file for the missing module.
133 2
|
4月前
|
中间件 Docker Python
【Azure Function】FTP上传了Python Function文件后,无法在门户页面加载函数的问题
通过FTP上传Python Function至Azure云后,出现函数列表无法加载的问题。经排查,发现是由于`requirements.txt`中的依赖包未被正确安装。解决方法为:在本地安装依赖包到`.python_packages/lib/site-packages`目录,再将该目录内容上传至云上的`wwwroot`目录,并重启应用。最终成功加载函数列表。
|
7月前
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
|
7月前
|
Python
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
|
13天前
|
缓存 安全 Java
《从头开始学java,一天一个知识点》之:字符串处理:String类的核心API
🌱 **《字符串处理:String类的核心API》一分钟速通!** 本文快速介绍Java中String类的3个高频API:`substring`、`indexOf`和`split`,并通过代码示例展示其用法。重点提示:`substring`的结束索引不包含该位置,`split`支持正则表达式。进一步探讨了String不可变性的高效设计原理及企业级编码规范,如避免使用`new String()`、拼接时使用`StringBuilder`等。最后通过互动解密游戏帮助读者巩固知识。 (上一篇:《多维数组与常见操作》 | 下一篇预告:《输入与输出:Scanner与System类》)
43 11

热门文章

最新文章