Azure Web函数:创建从http请求到inputBlob路径的绑定 期望情景

Azure Web函数:创建从http请求到inputBlob路径的绑定 期望情景,azure,azure-storage-blobs,azure-functions,arduino-esp8266,Azure,Azure Storage Blobs,Azure Functions,Arduino Esp8266,来自Arduino: 在Azure存储容器中拍摄照片并将图像作为水滴上传(工作正常) 使用带有blob名称和其他信息的HTTP调用Web函数(工作正常) 从Web功能 读取HTTP请求(工作正常) 使用HTTP请求中的信息读取blob(不起作用) 处理blob(尚未实现) 对Arduino作出回应 问题 我不知道如何从路径绑定到HTTP参数 Web函数配置 错误: Function ($HttpTriggerCSharp1) Error: Microsoft.Azure.WebJobs.Ho

来自Arduino:

  • 在Azure存储容器中拍摄照片并将图像作为水滴上传(工作正常)
  • 使用带有blob名称和其他信息的HTTP调用Web函数(工作正常) 从Web功能
  • 读取HTTP请求(工作正常)
  • 使用HTTP请求中的信息读取blob(不起作用)
  • 处理blob(尚未实现)
  • 对Arduino作出回应
问题 我不知道如何从路径绑定到HTTP参数

Web函数配置 错误:

Function ($HttpTriggerCSharp1) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HttpTriggerCSharp1'. Microsoft.Azure.WebJobs.Host: No binding parameter exists for 'blobName'.
原始非工作代码(以下为工作代码):

(我知道,msgType同时出现在URL和标题中。我尝试了不同的组合-没有效果)

如果我试图做的是不可能的,也欢迎其他建议。我只是需要一条通过的路

多亏了Tom Sun的提示,此代码才能正常工作。诀窍是在JSON中删除与存储blob的绑定,而只是直接从代码中调用blob

    #r "Microsoft.WindowsAzure.Storage"
    using Microsoft.WindowsAzure.Storage; // Namespace for CloudStorageAccount
    using Microsoft.WindowsAzure.Storage.Blob; // Namespace for Blob storage types
    using Microsoft.WindowsAzure.Storage.Queue;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Host;
    using System.Net;
    using System.IO;

    public static async Task<HttpResponseMessage> Run(HttpRequestMessage request, string inputBlob, TraceWriter log)
    {
        string msgType = request.GetQueryNameValuePairs()
            .FirstOrDefault(q => string.Compare(q.Key, "msgType", true) == 0)
            .Value;

        dynamic data = await request.Content.ReadAsAsync<object>();
        msgType = msgType ?? data?.msgType;

        string deviceId = data.deviceId;
        string blobName = data.BlobName;

        string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("nnriothubcontainer/" + deviceId);
        CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

        MemoryStream imageData = new MemoryStream();
        await blob.DownloadToStreamAsync(imageData);

        return msgType == null
            ? request.CreateResponse(HttpStatusCode.BadRequest, "HTTP parameter must contain msgType=<type> on the query string or in the request body")
            : request.CreateResponse(HttpStatusCode.OK, "Hello " + deviceId + " inputBlob size:" + imageData.Length);// + inputBlob );
    }
#r“Microsoft.WindowsAzure.Storage”
使用Microsoft.WindowsAzure.Storage;//CloudStorageAccount的命名空间
使用Microsoft.WindowsAzure.Storage.Blob;//Blob存储类型的命名空间
使用Microsoft.WindowsAzure.Storage.Queue;
使用Microsoft.Azure.WebJobs;
使用Microsoft.Azure.WebJobs.Host;
Net系统;
使用System.IO;
公共静态异步任务运行(HttpRequestMessage请求、字符串inputBlob、TraceWriter日志)
{
字符串msgType=request.GetQueryNameValuePairs()
.FirstOrDefault(q=>string.Compare(q.Key,“msgType”,true)==0)
价值
动态数据=wait request.Content.ReadAsAsync();
msgType=msgType??数据?.msgType;
字符串deviceId=data.deviceId;
字符串blobName=data.blobName;
string connectionString=AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
CloudStorageAccount-storageAccount=CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient=storageAccount.CreateCloudBlobClient();
CloudBlobContainer容器=blobClient.GetContainerReference(“nnriothubcontainer/”+设备ID);
CloudBlockBlob blob=container.GetBlockBlobReference(blobName);
MemoryStream imageData=新的MemoryStream();
等待blob.下载到StreamAsync(imageData);
返回msgType==null
?request.CreateResponse(HttpStatusCode.BadRequest,“HTTP参数必须在查询字符串或请求正文中包含msgType=)
:request.CreateResponse(HttpStatusCode.OK,“Hello”+deviceId+“inputBlob大小:”+imageData.Length);//+inputBlob);
}
在Azure存储容器中拍摄照片并将图像作为水滴上传(工作正常)

使用带有blob名称和其他信息的HTTP调用Web函数(工作正常)

读取HTTP请求(工作正常)

根据我的理解,您可以读取Http信息,包括blob uri、blob名称,并尝试在Azure Http触发器函数中操作存储blob。 如果是这样的话,我们可以参考。然后,我们可以使用Azure storeage SDK操作Azure存储。有关如何操作存储blob的更多详细信息,请参阅


您确定可以有2个输入操作吗?您的url看起来如何?你在哪里指定blobname:header,querystring?这篇文章可以给你一些线索:嗨,托马斯,在http请求期间,可以“同时”读取blob。(HTTP调用是触发器)。我可以用一个固定的blob名称来完成。还可以基于JSON中的绑定使blobname成为动态的。有将变量分配给“triggerqueues”的示例。我怀疑问题在于它是一个HTTP请求。2016年初的一篇帖子声称,只可能对整个请求实体进行绑定。他们还说他们有一个解决方案——但没有解释怎么做。不过这是一根很有毛的线,所以我不得不跳过它。谢谢!它花了一段时间才开始工作,但事实上,它非常简单。在原始问题中插入工作代码。
using System.Net;

public static async Task<HttpResponseMessage> Run(
    HttpRequestMessage request, 
    string blobName,           // DOES NOT WORK but my best guess so far
    string inputBlob, 
    TraceWriter log)
{

// parse query parameter   
string msgType = request.GetQueryNameValuePairs()
    .FirstOrDefault(q => string.Compare(q.Key, "msgType", true) == 0)
    .Value;

// Get request body
dynamic data = await request.Content.ReadAsAsync<object>();

// Set name to query string or body data  
msgType = msgType ?? data?.msgType;

string deviceId = data.deviceId;
string blobName = data.BlobName; // DOES NOT COMPILE

log.Info("blobName=" + blobName); // DOES NOT WORK
log.Info("msgType=" + msgType); 
log.Info("data=" + data); 

return msgType == null
    ? request.CreateResponse(HttpStatusCode.BadRequest, "HTTP parameter must contain msgType=<type> on the query string or in the request body")
    : request.CreateResponse(HttpStatusCode.OK, "Hello " + deviceId + " inputBlob:");// + inputBlob );

}
  https://xxxxxxprocessimagea.azurewebsites.net/api/HttpTriggerCSharp1?code=CjsO/EzhtUBMgRosqxxxxxxxxxxxxxxxxxxxxxxx0tBBqaiXNewn5A==&msgType=New image
   "deviceId": "ArduinoD1_001",
   "msgType": "New image",
   "MessageId": "12345",
   "UTC": "2017-01-08T10:45:09",
   "FullBlobName": "/xxxxxxcontainer/ArduinoD1_001/test.jpg",
   "BlobName": "test.jpg",
   "BlobSize": 9567,
   "WiFiconnects": 1,
   "ESPmemory": 7824,
   "Counter": 1
    #r "Microsoft.WindowsAzure.Storage"
    using Microsoft.WindowsAzure.Storage; // Namespace for CloudStorageAccount
    using Microsoft.WindowsAzure.Storage.Blob; // Namespace for Blob storage types
    using Microsoft.WindowsAzure.Storage.Queue;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Host;
    using System.Net;
    using System.IO;

    public static async Task<HttpResponseMessage> Run(HttpRequestMessage request, string inputBlob, TraceWriter log)
    {
        string msgType = request.GetQueryNameValuePairs()
            .FirstOrDefault(q => string.Compare(q.Key, "msgType", true) == 0)
            .Value;

        dynamic data = await request.Content.ReadAsAsync<object>();
        msgType = msgType ?? data?.msgType;

        string deviceId = data.deviceId;
        string blobName = data.BlobName;

        string connectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("nnriothubcontainer/" + deviceId);
        CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

        MemoryStream imageData = new MemoryStream();
        await blob.DownloadToStreamAsync(imageData);

        return msgType == null
            ? request.CreateResponse(HttpStatusCode.BadRequest, "HTTP parameter must contain msgType=<type> on the query string or in the request body")
            : request.CreateResponse(HttpStatusCode.OK, "Hello " + deviceId + " inputBlob size:" + imageData.Length);// + inputBlob );
    }
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;