Azure功能-调整存储在Blob容器中的图像的大小

汤玛士

我已经回答了与Azure Webjob有关的问题,并调整了存储为Blob的图像的大小,因此我尝试使用Function App

每次上传新的Blob时,我都会发送一条新的队列消息。我的功能由队列消息触发,并绑定到上传的Blob。我还有第二个输入绑定,该输入绑定绑定到另一个CloudBlobContainer,以便能够将新调整大小的图像上传到另一个blob容器。

我的函数看起来像这样:

#r "System.Web"
using System.IO;
using System.Web;
using ImageResizer;
using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;

private static readonly int[] Sizes = { 800, 500, 250 };

public static void Run(string filename, Stream blobStream, CloudBlobContainer container, TraceWriter log)
{
    log.Verbose($"C# Queue trigger function processed: {filename}");
    // Extract the filename  and the file extension
    var name = Path.GetFileNameWithoutExtension(filename);
    var ext = Path.GetExtension(filename);

    // Get the mime type to set the content type
    var mimeType = MimeMapping.GetMimeMapping(filename);

    foreach (var width in Sizes)
    {
        // Set the position of the input stream to the beginning.
        blobStream.Seek(0, SeekOrigin.Begin);

        // Get the output stream
        var outputStream = new MemoryStream();
        ResizeImage(blobStream, outputStream, width);

        // Get the blob reference
        CloudBlockBlob blob = container.GetBlockBlobReference($"{name}-w{width}.{ext}");

        // Set the position of the output stream to the beginning.
        outputStream.Seek(0, SeekOrigin.Begin);
        blob.UploadFromStream(outputStream);

        // Update the content type =>  don't know if required
        blob.Properties.ContentType = mimeType;
        blob.SetProperties();
    }               
}

private static void ResizeImage(Stream input, Stream output, int width)
{
    var instructions = new Instructions
    {
        Width = width,
        Mode = FitMode.Carve,
        Scale = ScaleMode.Both
    };
    var imageJob = new ImageJob(input, output, instructions);

    // Do not dispose the source object
    imageJob.DisposeSourceObject = false;
    imageJob.Build();
}

关联function.json文件:

{
"bindings": [
  {
    "queueName": "newfileuploaded",
    "connection": "crazytunastorageaccount_STORAGE",
    "name": "filename",
    "type": "queueTrigger",
    "direction": "in"
  },
  {
    "path": "input-images/{queueTrigger}",
    "connection": "crazytunastorageaccount_STORAGE",
    "name": "blobStream",
    "type": "blob",
    "direction": "in"
  },
  {
    "name": "container",
    "type": "blob",
    "path": "output-images",
    "connection": "crazytunastorageaccount_STORAGE",
    "direction": "in"
  }
],
"disabled": false
}

project.json文件:

{
"frameworks": {
  "net46":{
    "dependencies": {
      "ImageResizer": "4.0.5",
      "WindowsAzure.Storage": "4.3.0"
    }
  }
 }
}

现在,当我编译函数时,我总是会遇到此错误:

Microsoft.Azure.WebJobs.Host:错误索引方法“ Functions.ResizeBlobImage”。Microsoft.Azure.WebJobs.Host:无法将Blob绑定为“ Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer”。

目前是否支持该类型?

数学

CloudBlobContainer的。我现在自己尝试了一个快速示例,下面的功能对我有用,使用了上面显示的相同绑定元数据。我还在中使用了相同版本的WebJobs SDK project.json

using System;
using Microsoft.WindowsAzure.Storage.Blob;

public static void Run(
    string blobTrigger, Stream inputBlob, Stream outputBlob,
    CloudBlobContainer container, TraceWriter log)
{
    log.Info($"Container name: {container.Name}");

    log.Info($"C# Blob trigger function processed {blobTrigger}");
    inputBlob.CopyTo(outputBlob);        
}

不知道为什么这对您不起作用。我不时看到一些Portal故障(我们正在修复的错误),这些故障有时会引起问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Azure功能-调整存储在Blob容器中的图像的大小

来自分类Dev

在Azure Blob存储中调整图像大小

来自分类Dev

在Azure Blob存储中调整图像大小

来自分类Dev

Azure功能和Azure Blob存储

来自分类Dev

调整图像大小的Ubuntu功能

来自分类Dev

无法在Azure功能中登录Azure服务

来自分类Dev

从Azure中的表存储触发功能

来自分类Dev

从Azure中的表存储触发功能

来自分类Dev

在网站中嵌入存储在Azure BLOB存储中的图像

来自分类Dev

调整大小时,使用laravel中的asset功能加载图像

来自分类Dev

用于在Azure Blob存储中存储图像的共享访问策略

来自分类Dev

在公共容器中匿名列出Azure存储Blob

来自分类Dev

删除Azure Blob存储容器中的文件夹

来自分类Dev

通过 URL 列出 Azure 存储容器中的 blob

来自分类Dev

Azure Blob存储列表容器和Blob

来自分类Dev

Azure博客功能触发容器错误

来自分类Dev

Azure 表存储快照/备份功能

来自分类Dev

用于图像发布的 Azure 存储功能是什么?

来自分类Dev

从Azure Blob存储访问图像

来自分类Dev

如何停止从Azure功能中的特定功能发送遥测?

来自分类Dev

云功能:调整大小的图像无法加载

来自分类Dev

使用Azure功能将文件下载并存储到Azure

来自分类Dev

在Visual Studio中调试Azure功能

来自分类Dev

在Azure功能中启用同步IO

来自分类Dev

Azure功能在调试中记录消息

来自分类Dev

获取 azure 中的功能应用模板

来自分类Dev

Azure存储Blob容器Vituval文件夹图像在JAVA中下载

来自分类Dev

如何限制或更改Azure BLOB容器的大小?

来自分类Dev

无法使用Azure功能节点将文件上传到Azure Blob存储