标签: azure-blob-storage

如何将对象传输到 Azure Blob 存储而不将文件保存在本地存储上?

我一直在关注GitHub 上的这个示例,将文件传输到 Azure Blob 存储。该程序在本地MyDocuments文件夹中创建一个文件以上传到 blob 容器。创建文件后,会将其上传到容器。是否可以在内存中创建 JSON 对象并将其发送到 Azure Blob 存储,而无需先将该文件写入硬盘?

namespace storage_blobs_dotnet_quickstart
{
    using Microsoft.Azure.Storage;
    using Microsoft.Azure.Storage.Blob;
    using System;
    using System.IO;
    using System.Threading.Tasks;

    public static class Program
    {
        public static void Main()
        {
            Console.WriteLine("Azure Blob Storage - .NET quickstart sample");
            Console.WriteLine();
            ProcessAsync().GetAwaiter().GetResult();

            Console.WriteLine("Press any key to exit the sample application.");
            Console.ReadLine();
        }

        private static async Task ProcessAsync()
        {
            CloudStorageAccount storageAccount = null;
            CloudBlobContainer cloudBlobContainer = null;
            string sourceFile = null;
            string destinationFile = null; …
Run Code Online (Sandbox Code Playgroud)

c# azure .net-core azure-blob-storage

5
推荐指数
1
解决办法
4274
查看次数

查看哪个用户将文件上传到 azure blob 存储容器

有没有办法知道哪个用户在 azure blob 容器中上传了文件?您必须手动将其添加到元数据中吗?

azure azure-blob-storage

5
推荐指数
1
解决办法
2843
查看次数

如何将文件添加到 Azurite [Azure 存储模拟器]

我很难弄清楚如何将文件添加到该模拟器,以便在本地测试 azure blob 的不同操作。

c# azure azure-blob-storage

5
推荐指数
1
解决办法
6606
查看次数

具有事件中心触发器的 Azure 函数写入重复消息

我有一个带有事件中心触发器的 Azure 函数。该中心接收来自设备的消息并将它们存储在 Blob 中。最近,我注意到重复的消息存储在 blob 中。Blob 存储中的文件按上次修改日期排序,如果您查看屏幕截图,您会发现情况并非如此。以前有人见过这个问题吗?

我还有一个正在写入 cosmos DB 的 Azure 函数,并且对于 blob 中的重复消息,cosmos 中没有相应的重复消息。

我还连接了时间序列见解,它也没有任何重复的消息。

我打开了事件中心捕获,那里也没有重复的消息。

这是屏幕截图。

在此输入图像描述

第一列是事件中心排队时间的 unix 时间戳。如果我没有与文件名关联的 guid,它会抛出异常。这是将数据存储在 blob 中的片段。

dynamic msg = JObject.Parse(myEventHubMessage);
string deviceId = msg.deviceId;
if (deviceId == "5Y.....")
{
           var filename = "_" + ((DateTimeOffset)enqueuedTimeUtc).ToUnixTimeSeconds() + "_" + Guid.NewGuid().ToString() + ".json";
        
           var containerName = "containerName/";
        
           var path = containerName + deviceId + "/" + filename;
        
           using (var writer = binder.Bind<TextWriter>(new BlobAttribute(path)))
           {
                writer.Write(myEventHubMessage);
           }
 }
Run Code Online (Sandbox Code Playgroud)

这里的逻辑非常简单。如果事件到达事件中心,则会触发该函数并将数据存储在 Azure Blob 中。

azure-eventhub azure-blob-storage azure-functions

5
推荐指数
1
解决办法
4040
查看次数

如何在React Native应用程序中使用Axios将图像和视频作为blob正确上传到Azure存储容器?

我正在开发一个 React Native 应用程序,我需要将图像或视频作为 blob 上传到 Azure 存储帐户。目前我正在处理图像上传,但我想在这个问题中添加视频,因为视频将是下一步。我尝试了很多方法将图像上传到 Azure 存储,但无法使用 Axios 从 RN 应用程序正确上传图像。我正在使用 SAS 令牌生成上传 url,以便我可以与设备共享来自后端服务器的该 url,以便能够从设备上传图像或视频。我曾经Postman测试过该网址,一切都很好!我可以Postman将图像作为二进制正文上传。我使用了Postman显示Axios代码示例的代码生成,但我不确定此处的文件内容意味着什么。让我退后一点。

在这个React Native应用程序中,我使用react-native-image-picker从图库中选择图像并将路径传递给辅助类,我使用react-native-fs来获取图像只是为了确保它存在以及所有内容和我还base64RNFS获取字符串。现在我有了图像路径和图像的 base64 字符串,我想使用 Axios 将其上传到 Azure 服务器。我尝试了一些事情。其中一件事是来自邮递员的示例代码,但正如我所说,我不确定如何将文件内容作为示例代码中显示的数据对象传递,即

const axios = require('axios');
let data = '<file contents here>'; // <--- I don't know this

let config = {
  method: 'put',
  url: 'https://azure.blob.url/container/blob?sastoken=1234',
  headers: { 
    'x-ms-blob-type': 'BlockBlob', 
    'Content-Type': 'image/jpeg'
  },
  data : data
};

axios(config) …
Run Code Online (Sandbox Code Playgroud)

javascript azure react-native azure-blob-storage axios

5
推荐指数
0
解决办法
694
查看次数

Azure 权限:无权执行此操作

所以我有一个数据工厂,它调用一个读取 blob 存储的 Azure 函数。

我不明白为什么我会收到此错误。“此请求无权执行此操作”。是数据工厂、azure 存储还是azure 功能的问题吗?

我还向 Storage Blob Data Contributor 添加了服务主体,但没有成功。

我应该在存储资源管理器中对此特定文件夹添加什么权限?在此输入图像描述

{
    "name": "TPFunction",
    "instanceId": "4ef6513ebfc6bb",
    "runtimeStatus": "Failed",
    "input": {
        "environment": "dev",
        "DateToProcess": "2013-04-08",
        "SourceStorageType": "AdlsGen2",
        "SourceAccountName": "storage06",
        "SourceBlobContainer": "data",
        "SourceFilePath": "file/file/file"
    },
    "customStatus": null,
    "output": "Orchestratorfunction 'TPFunction' failed: Following error occurred during execution: The activity function 'TPFunction' failed: \"Error occurred getting list of files: This request is not authorized to perform this operation using this permission.\nRequestId:7b5e-e4a603\nTime:2013-04-08:02:27.0924606Z\r\nStatus: 403 (This request is not authorized to perform this …
Run Code Online (Sandbox Code Playgroud)

permissions azure azure-data-factory azure-blob-storage azure-functions

5
推荐指数
1
解决办法
3万
查看次数

使用 .NET SDK 12 从 Azure Blob 存储中的特定目录/文件夹获取文件

我需要列出“Test”文件夹中特定目录中的所有文件,不包括“Test2”。我尝试使用“test”作为前缀,但它返回两个文件夹。

容器:“myContainer”

测试:

  • 文件1.jpg
  • 文件2.jpg

测试2:

  • 文件1.jpg

我尝试了以下操作,但它返回带有输出的文件夹和路径:

  • 测试/file1.jpg
  • 测试/file2.jpg
  • 测试2/文件1.jpg

我可以只返回文件而不是路径吗?

  • 文件1.jpg

  • 文件2.jpg

         var blobUri = new Uri($"https://{myAccountName}.blob.core.windows.net/");
         StorageSharedKeyCredential credential = new StorageSharedKeyCredential(myAccountName, myKey);
         BlobServiceClient service = new BlobServiceClient(blobUri, credential);
         BlobContainerClient container = service.GetBlobContainerClient("myContainer");
         AsyncPageable<BlobItem> blobs = container.GetBlobsAsync(prefix: "test");
    
         List<Result> results = new List<Result>();
         await foreach (var blob in blobs)
         {
             var result = new Result();
             result.FileName = blob.Name;
             results.Add(result);
         }
    
    Run Code Online (Sandbox Code Playgroud)

.net azure azure-blob-storage

5
推荐指数
1
解决办法
1万
查看次数

公开 Blob 存储并上传到其中

尝试使用curl命令上传到blob存储

curl --upload-file <file> --url "https://<storage-account-name>.blob.core.windows.net/<container-name>/<file>"
Run Code Online (Sandbox Code Playgroud)

但不断收到“HTTP/1.1 404 指定的资源不存在”。我将存储和容器都公开,容器的访问级别设置为“容器”,不知道还可以尝试什么。我错过了什么吗?

azure azure-blob-storage

5
推荐指数
1
解决办法
4724
查看次数

如何集成测试Azure Blob存储?

我正在开发一个企业业务项目,需要将应用程序从本地迁移到 Azure 云。

某些应用程序需要 Azure Blob 存储。所有 Azure 云基础设施都可以使用 Manage Identity 进行访问,业务要求是在无法访问 Azure 门户的情况下测试和验证 Azure Blob 方法,开发人员只能访问任何非生产或生产的存储资源。也就是说,该公司要求我们在将代码推送到云之前通过在本地和 GitHub 工作流程上进行测试来使所有存储功能正常工作。

当然,我可以启动我的个人 Azure 帐户并使用它,但仍然会使用我的帐户作为游乐场进行测试,但并不是真正可用的测试。

通用测试 Azure Blob 存储的整个想法,无需对 Blob 存储有任何类型的访问权限。

这可能吗?我怎样才能实现这一目标?

以下是我针对 Azure Blob 的工作 POC 方法:

private readonly BlobContainerClient _blobContainerClient;

public AzureBlobStorage(string connectionString, string container)
{
    _blobContainerClient = new BlobContainerClient(connectionString, container);
    _blobContainerClient.CreateIfNotExists();
}

public async Task<string> ReadTextFile(string filename)
{
    var blob = _blobContainerClient.GetBlobClient(filename);
    if (!await _blobContainerClient.ExistsAsync()) return string.Empty;
    var reading = await blob.DownloadStreamingAsync();
    StreamReader reader = new StreamReader(reading.Value.Content);
    return await reader.ReadToEndAsync(); …
Run Code Online (Sandbox Code Playgroud)

.net c# azure azure-blob-storage

5
推荐指数
1
解决办法
3974
查看次数

如何验证 Azure Blob 存储共享访问签名 (SAS) URL?

我的应用程序允许用户输入 Azure Blob 存储 SAS URL。我将如何去验证它?我正在使用Azure 存储 Blob 客户端库,并且似乎没有任何方法可以在不实际执行 Blob 操作(我不想这样做)的情况下验证 SAS URL。

验证操作可以是异步的,并在必要时涉及 API 调用(即可以通过按钮触发)。

public class SASURLValidator
{
    public async Task<bool> ValidateSASURL(string sasURL)
    {
        // What goes here?
    }

    public async Task Test()
    {
        var result = await ValidateSASURL("https://blobstorageaccountname.blob.core.windows.net/containerName?sp=w&st=2022-02-15T02:07:49Z&se=2022-03-15T10:07:49Z&spr=https&sv=2020-08-04&sr=c&sig=JDFJEF342JDSFJIERJsdjfkajiwSKDFJIQWJIFJSKDFJWE%3D")
        // result should be true if the above is a valid SAS
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# azure-storage azure-blob-storage shared-access-signatures

5
推荐指数
1
解决办法
3293
查看次数