我的 Azure 存储输出 blob 从未显示

My Azure Storage output blob never shows up

我正在尝试构建一个简单的 Azure 函数,该函数基于 ImageResizer example, but uses the Microsoft Cognitive Server Computer Vision API 来调整大小。

我有 working code for the Computer Vision API,我已将其移植到 Azure 函数中。

一切似乎都正常(没有错误),但我的输出 blob 从未保存或显示在存储容器中。不确定我做错了什么,因为没有错误可以处理。

我的CSX(C#函数代码)如下

using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;

public static void Run(Stream original, Stream thumb, TraceWriter log)
{
    //log.Verbose($"C# Blob trigger function processed: {myBlob}. Dimensions");
    string _apiKey = "PutYourComputerVisionApiKeyHere";
    string _apiUrlBase = "https://api.projectoxford.ai/vision/v1.0/generateThumbnail";
    string width = "100";
    string height = "100";
    bool smartcropping = true;

    using (var httpClient = new HttpClient())
    {
        //setup HttpClient
        httpClient.BaseAddress = new Uri(_apiUrlBase);
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _apiKey);

        //setup data object
        HttpContent content = new StreamContent(original);
        content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/octet-stream");

        // Request parameters
        var uri = $"{_apiUrlBase}?width={width}&height={height}&smartCropping={smartcropping}";

        //make request
        var response = httpClient.PostAsync(uri, content).Result;

        //log result
        log.Verbose($"Response: IsSucess={response.IsSuccessStatusCode}, Status={response.ReasonPhrase}");

        //read response and write to output stream
        thumb = new MemoryStream(response.Content.ReadAsByteArrayAsync().Result);
    }
}

我的函数json如下

{
  "bindings": [
    {
      "path": "originals/{name}",
      "connection": "thumbnailgenstorage_STORAGE",
      "name": "original",
      "type": "blobTrigger",
      "direction": "in"
    },
    {
      "path": "thumbs/%rand-guid%",
      "connection": "thumbnailgenstorage_STORAGE",
      "type": "blob",
      "name": "thumb",
      "direction": "out"
    }
  ],
  "disabled": false
}

我的 Azure 存储帐户名为 'thumbnailgenstorage',它有两个名为 'originals' and 'thumbs' 的容器。存储帐户密钥是 KGdcO+hjvARQvSwd2rfmdc+rrAsK0tA5xpE4RVNmXZgExCE+Cyk4q0nSiulDwvRHrSAkYjyjVezwdaeLCIb53g==.

我非常高兴人们使用我的密钥来帮助我解决这个问题! :)

我现在开始工作了。我写错了输出流。

此解决方案是一个 Azure 函数,它在 blob 到达名为 'Originals' 的 Azure Blob 存储容器时触发,然后使用 Computer Vision API 巧妙地调整图像大小并存储在名为 'Thumbs'.

的不同 blob 容器

这是工作的 CSX(c# 脚本):

using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;

public static void Run(Stream original, Stream thumb, TraceWriter log)
{
    int width = 320;
    int height = 320;
    bool smartCropping = true;
    string _apiKey = "PutYourComputerVisionApiKeyHere";
    string _apiUrlBase = "https://api.projectoxford.ai/vision/v1.0/generateThumbnail";

    using (var httpClient = new HttpClient())
    {
        httpClient.BaseAddress = new Uri(_apiUrlBase);
        httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _apiKey);
        using (HttpContent content = new StreamContent(original))
        {
            //get response
            content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/octet-stream");
            var uri = $"{_apiUrlBase}?width={width}&height={height}&smartCropping={smartCropping.ToString()}";
            var response = httpClient.PostAsync(uri, content).Result;
            var responseBytes = response.Content.ReadAsByteArrayAsync().Result;

            //write to output thumb
            thumb.Write(responseBytes, 0, responseBytes.Length);
        }
    }
}

这里是整合JSON

{
  "bindings": [
    {
      "path": "originals/{name}",
      "connection": "thumbnailgenstorage_STORAGE",
      "name": "original",
      "type": "blobTrigger",
      "direction": "in"
    },
    {
      "path": "thumbs/{name}",
      "connection": "thumbnailgenstorage_STORAGE",
      "name": "thumb",
      "type": "blob",
      "direction": "out"
    }
  ],
  "disabled": false
}