gpt4 book ai didi

node.js - Azure函数JS : get image from blob and transform to base64

转载 作者:行者123 更新时间:2023-12-03 02:35:20 26 4
gpt4 key购买 nike

我正在开发一个azure函数,在node js中运行。此函数应该从 blob 获取图像并将其转换为 base64 字符串。问题是当我调用toString('base64')时我的函数挂起(看起来像一些无限循环)。我该如何解决这个问题以及什么可能导致该问题?

函数.json

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
],
"route": "my_func"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "templateImage",
"type": "blob",
"path": "assets/{templateImage}.jpg",
"dataType": "binary",
"connection": "Storage",
"direction": "in"
}
]
}

index.js

module.exports = async function (context, req) {
let templateImage = context.bindings.templateImage; // This is Buffer.
console.log(templateImage); // I can log it. Will see something like this: <Buffer ff d8 ff e0 00...
console.log(templateImage.toString('base64')); // I want to get base64, but after calling it my function is stuck.
...
}

更新:我认为值得一提的是,该功能仅在本地开发中有效。在 azure 门户中,它进行了转换,但结果看起来很奇怪: ����\u0000\u0010JFIF\u0000\u0001\u0002\u0001\u0001,\u0001,\u0000\u0000��\u0000,Photoshop 。虽然它应该是这样的: data:image/jpeg;base64,/9j/4AAQ...

最佳答案

我在我的网站上进行了测试,效果非常好。您可以引用以下代码进行排查。

在index.js中,注意添加myinput int参数:

module.exports = async function (context, req,myinput) {
context.log('JavaScript HTTP trigger function processed a request.');
let me = context.bindings.myinput;
console.log(me);
console.log(me.toString('base64'));
}

本地主机中的快照: enter image description here

门户中的快照: enter image description here

关于node.js - Azure函数JS : get image from blob and transform to base64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63372956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com