1. <tfoot id='7LMqe'></tfoot>

    <small id='7LMqe'></small><noframes id='7LMqe'>

    • <bdo id='7LMqe'></bdo><ul id='7LMqe'></ul>

    <legend id='7LMqe'><style id='7LMqe'><dir id='7LMqe'><q id='7LMqe'></q></dir></style></legend>

    <i id='7LMqe'><tr id='7LMqe'><dt id='7LMqe'><q id='7LMqe'><span id='7LMqe'><b id='7LMqe'><form id='7LMqe'><ins id='7LMqe'></ins><ul id='7LMqe'></ul><sub id='7LMqe'></sub></form><legend id='7LMqe'></legend><bdo id='7LMqe'><pre id='7LMqe'><center id='7LMqe'></center></pre></bdo></b><th id='7LMqe'></th></span></q></dt></tr></i><div id='7LMqe'><tfoot id='7LMqe'></tfoot><dl id='7LMqe'><fieldset id='7LMqe'></fieldset></dl></div>

    1. 使用 C# 从 Azure Blob 复制到 AWS S3

      时间:2023-10-05
    2. <i id='KfJN5'><tr id='KfJN5'><dt id='KfJN5'><q id='KfJN5'><span id='KfJN5'><b id='KfJN5'><form id='KfJN5'><ins id='KfJN5'></ins><ul id='KfJN5'></ul><sub id='KfJN5'></sub></form><legend id='KfJN5'></legend><bdo id='KfJN5'><pre id='KfJN5'><center id='KfJN5'></center></pre></bdo></b><th id='KfJN5'></th></span></q></dt></tr></i><div id='KfJN5'><tfoot id='KfJN5'></tfoot><dl id='KfJN5'><fieldset id='KfJN5'></fieldset></dl></div>
        <bdo id='KfJN5'></bdo><ul id='KfJN5'></ul>
          <tfoot id='KfJN5'></tfoot>
          <legend id='KfJN5'><style id='KfJN5'><dir id='KfJN5'><q id='KfJN5'></q></dir></style></legend>

          1. <small id='KfJN5'></small><noframes id='KfJN5'>

              <tbody id='KfJN5'></tbody>

              • 本文介绍了使用 C# 从 Azure Blob 复制到 AWS S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                请注意,这是我第一次在 C# 中做任何事情,所以请善待,我可能犯了一些非常基本的错误.(是的,我知道我不应该对密钥进行硬编码,但会在代码执行我想要的操作时修复它).

                Please note that this is my first time doing anything in C# so please be kind, I might have made some very basic mistakes. (and yes I know I shouldnt hardcode keys but will fix it when the code does what I want).

                我正在尝试创建一个 Azure 函数,它将任何新项目从 Blob 存储复制到 AWS S3.我已经设法使用本文中的代码从 blob 复制到 blob:https://cmatskas.com/copy-azure-blob-data-between-storage-accounts-using-functions/

                I am trying to create an Azure Function that copies any new items from Blob storage to AWS S3. I have managed to copy from blob to blob using the code from this article: https://cmatskas.com/copy-azure-blob-data-between-storage-accounts-using-functions/

                我已尝试修改该代码以保存到 AWS S3 存储桶.虽然此代码成功编译并为我提供了成功的日志条目,但它不会复制任何文件.有什么想法吗?

                I have tried to amend that code to instead save to an AWS S3 bucket. While this code compiles successfully and gives me successful log entires, it doesn't copy any files. Any ideas?

                using System;
                using System.IO;
                using Amazon.S3;
                using Amazon.S3.Model;
                using Amazon.S3.Transfer;
                using Microsoft.Azure;
                using Microsoft.WindowsAzure.Storage;
                using Microsoft.WindowsAzure.Storage.Blob;
                
                public async static void Run(CloudBlockBlob myBlob, TraceWriter log) 
                {
                    await CopyBlob(myBlob, log);
                }
                
                private async static Task CopyBlob(CloudBlockBlob myBlob, TraceWriter log)
                {
                    var existingBucketName = "bucketname";
                    var keyName = "backup";
                    var accessKey = "key";
                    var secretKey = "secretkey";
                
                    TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(accessKey,secretKey,Amazon.RegionEndpoint.eu-west-2));
                
                    log.Info("Starting Copy");
                
                    try{
                        using (var stream = await myBlob.OpenReadAsync())
                        {
                            await fileTransferUtility.UploadAsync(stream, existingBucketName, keyName);
                        }
                        log.Info("Copy completed");
                
                    }
                    catch(Exception ex){
                        log.Error(ex.Message);
                        log.Info("Copy failed");
                    }
                    finally{
                        log.Info("Operation completed");
                    }
                }
                

                让它适用于将来发现此问题的任何人.

                Got it working for anyone finding this in the future.

                using System;
                using System.IO;
                using Amazon.S3;
                using Amazon.S3.Model;
                using Amazon.S3.Transfer;
                using Microsoft.Azure;
                using Microsoft.WindowsAzure.Storage;
                using Microsoft.WindowsAzure.Storage.Blob;
                
                public async static void Run(CloudBlockBlob myBlob, TraceWriter log) 
                {
                    await CopyBlob(myBlob, log);
                }
                
                private async static Task CopyBlob(CloudBlockBlob myBlob, TraceWriter log)
                {
                    var existingBucketName = "bucketname";
                    var keyName = myBlob.Name;
                    var accessKey = "accesskey";
                    var secretKey = "secretkey";
                
                    TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(accessKey,secretKey,Amazon.RegionEndpoint.eu-west-2));
                
                    log.Info("Starting Copy");
                
                    try{
                        using (var stream = await myBlob.OpenReadAsync())
                        {
                            await fileTransferUtility.UploadAsync(stream,existingBucketName,keyName);
                        }
                        log.Info("Copy completed");
                
                    }
                    catch(Exception ex){
                        log.Error(ex.Message);
                        log.Info("Copy failed");
                    }
                    finally{
                        log.Info("Operation completed");
                    }
                }
                

                推荐答案

                您应该会看到有关此问题的警告,但您的 void 方法可能会导致此问题.

                You should be seeing a warning about this, but your void method is likely causing the issue here.

                请将您的功能代码更新为以下内容:

                Please update your function code to the following:

                public async static Task Run(CloudBlockBlob myBlob, TraceWriter log) 
                {
                    await CopyBlob(myBlob, log);
                }
                

                注意从 voidTask

                这篇关于使用 C# 从 Azure Blob 复制到 AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为 Azure 函数的输出 blob 生成名称 下一篇:Azure 函数 - 函数应该写在静态类中

                相关文章

                <i id='tvQ43'><tr id='tvQ43'><dt id='tvQ43'><q id='tvQ43'><span id='tvQ43'><b id='tvQ43'><form id='tvQ43'><ins id='tvQ43'></ins><ul id='tvQ43'></ul><sub id='tvQ43'></sub></form><legend id='tvQ43'></legend><bdo id='tvQ43'><pre id='tvQ43'><center id='tvQ43'></center></pre></bdo></b><th id='tvQ43'></th></span></q></dt></tr></i><div id='tvQ43'><tfoot id='tvQ43'></tfoot><dl id='tvQ43'><fieldset id='tvQ43'></fieldset></dl></div>
                1. <legend id='tvQ43'><style id='tvQ43'><dir id='tvQ43'><q id='tvQ43'></q></dir></style></legend>
                  • <bdo id='tvQ43'></bdo><ul id='tvQ43'></ul>

                  <small id='tvQ43'></small><noframes id='tvQ43'>

                2. <tfoot id='tvQ43'></tfoot>