【问题标题】:Azure Function - Trigger blob storage copy when last modifiedAzure 函数 - 上次修改时触发 blob 存储副本
【发布时间】:2022-02-02 20:46:39
【问题描述】:

第一次使用 azure 函数。在我的 run.csx 中有

public static void Run(Stream myBlob, string name, ILogger log)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}

在我的functions.json中我有

{
  "bindings": [
    {
      "name": "myBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "insights-logs-auditlogs/{name}",
      "connection": "stnhnmspsplunkmgmt_STORAGE"
    },
    {
      "name": "Output",
      "path": "test/{rand-guid}",
      "connection": "sttestfuncapptest_STORAGE",
      "direction": "out",
      "type": "blob"
    }
  ]
}

当我编辑容器中的现有文件时,这可以正常工作,但是当发生更改时,我无法弄清楚如何进行复制。任何人都可以指出我正确的方向。非常感谢。

【问题讨论】:

  • 我不确定问题是什么。 “当我编辑现有文件时,这很好用”,“无法确定何时发生更改”。当有人编辑现有文件时,就意味着发生了变化。
  • 嗨@henke!如果我的答案对您有帮助,您可以接受它作为答案(单击答案旁边的复选标记将其从灰色切换为已填充)。这对其他社区成员可能是有益的。谢谢你:)

标签: azure function azure-blob-storage


【解决方案1】:

当检测到新的或更新的 Blob 时,Blob 存储触发器会启动一个函数。 当在 samples-workitems 容器中添加或更新 blob 时,this blob trigger for azure 函数会写入日志。

尝试为具有所需权限且读取最少的 blob 创建一个 SAS URL,然后将其用于 c# 中的文件复制并在 azure 中发布。

请查看SO reference

[FunctionName("MyBlobTrigger")]
public async void Run([BlobTrigger("uploads/{name}", Connection = "UploadStorageAccount")]CloudBlockBlob myBlob, string name, ILogger log, CancellationToken cancellationToken)
{

    // Get SAS for the blob
    var sasToken = myBlob.GetSharedAccessSignature();
    
    //SAS URI
    var blobSasUrl = $"{myBlob.Uri.AbsoluteUri}{sasToken}";

    ShareClient share = new ShareClient(storageConnection, fileShareName);

    ShareDirectoryClient directory = share.GetRootDirectoryClient();
    ShareFileClient fileShare = directory.GetFileClient(name);

    ShareClient share = new ShareClient(storageConnection, fileShareName);

    ShareDirectoryClient directory = share.GetRootDirectoryClient();
    ShareFileClient fileShare = directory.GetFileClient(name);

    try
    {
        
        fileShare.Create(myBlob.Properties.Length);
       
 //Copy blob's contents to storage file using async file copy.
        //await fileShare.StartCopyAsync(new Uri(blobSasUrl));
    }
}

其他参考资料:

  1. c# - Azure Function Blob Trigger copy file to File Share - Stack Overflow
  2. ADF: copy last modified blob - Microsoft Q&A / Microsoft Docs
  3. LastModifiedDate with Azure Data Factory | Azure Blog and Updates | Microsoft Azure

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2021-11-05
    • 2019-01-11
    相关资源
    最近更新 更多