Azure functions Azure函数加载blob并将其直接发送到context.res
我认为从azure存储容器加载blob并将其写入HTTP响应非常容易,但我无法让它工作 我声明了一个输入blob,如下所示:Azure functions Azure函数加载blob并将其直接发送到context.res,azure-functions,Azure Functions,我认为从azure存储容器加载blob并将其写入HTTP响应非常容易,但我无法让它工作 我声明了一个输入blob,如下所示: { "bindings": [ { "authLevel": "function", "type": "httpTrigger", "direction": "in", "name": "req", "route": "resizeImage" }, { "type": "
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "resizeImage"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "blob",
"name": "imageBlob",
"path": "images/{name}",
"connection": "ng1_STORAGE",
"direction": "in"
}
],
"disabled": false
}
这是一个HTTP触发器,所以我只调用URLresizeImage?name=image1.png
,它为我提供了context.bindings.imageBlob
作为blob数据
然而,第一个问题是水滴的大小不对。我尝试用以下两个图像输出imageBlob.length
的JSON:
1) 磁盘上的cat.png=272228字节,但imageBlob.length=258032字节
2) 磁盘上的dog.png=1569964字节,但imageBlob.length=15173390字节
所以
- 我肯定知道文件正在被找到和加载,因为这些图像的大小接近它们应该的大小
- 我猜
是某种流对象?(我看到C#签名是Stream)李>imageBlob
- 为什么.length属性只提供磁盘上大约95%的映像大小
imageBlob.length
,但是图像当然是不完整的
context.res = {
body: new Buffer(context.bindings.imageBlob, 'binary'),
headers: {
'Content-Type': 'image/png'
}
我将使用夏普图像库来处理它,但我现在甚至不能返回原始图像!如何将blob作为HTTP响应返回?我尝试使用不同的文件名将其保存回Azure,结果显示为内容类型为
八位字节流
然后,我可以搜索并发现,在Javascript中,除非指定类型,否则blob显然不会正确出现
因此,一旦我添加了“dataType”:“binary”
这个blob就没问题了
{
"type": "blob",
"name": "imageBlob",
"dataType": "binary",
"path": "images/{name}",
"connection": "ng_STORAGE",
"direction": "in"
},
不幸的是,这没有显示在Azure门户中,您必须手动编辑它
我尝试用不同的文件名将其保存回Azure,结果显示为内容类型为Octet-Stream
然后,我可以搜索并发现,在Javascript中,除非指定类型,否则blob显然不会正确出现
因此,一旦我添加了“dataType”:“binary”
这个blob就没问题了
{
"type": "blob",
"name": "imageBlob",
"dataType": "binary",
"path": "images/{name}",
"connection": "ng_STORAGE",
"direction": "in"
},
不幸的是,这没有显示在Azure门户中,您必须手动编辑它