标签: azure-blob-storage

检查Azure存储中是否存在Blob

我有一个非常简单的问题(我希望!) - 我只是想知道一个特定容器中是否存在一个blob(我已经定义了一个名字).我会下载它,如果它确实存在,如果它不存在,那么我会做其他事情.

我已经对intertubes进行了一些搜索,显然曾经有一个名为DoesExist的函数或类似的东西......但是就像许多Azure API一样,这似乎不再存在(或者如果有的话)非常巧妙伪装的名字).

c# azure azure-blob-storage

119
推荐指数
6
解决办法
6万
查看次数


azure blob storage"找不到有效的帐户信息组合"

我有一个MVC4项目,我正在使用Azure网站预览运行.

我的问题是,当我将网站部署到azure时,我无法将blob上传到我的blob存储容器中,但是当我在本地调试时上传工作正常.

这是我在部署时获得的异常和堆栈跟踪,我尝试上传到容器:

找不到有效的帐户信息组合.在Microsoft.WindowsAzure.Storage.CloudStorageAccount.b__0(字符串ERR)在Microsoft.WindowsAzure.Storage.CloudStorageAccount.TryParse(字符串s CloudStorageAccount&accountInformation,Action`1误差)在Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(字符串的connectionString) at MyProj.Controllers.ImageController.Upload(ImageViewModel model)

具体来说,根据堆栈跟踪,它是失败的.Parse方法.

我用来连接blob存储的代码直接来自azure how-to文档:

string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
Run Code Online (Sandbox Code Playgroud)

再次,当我在我的开发盒上本地运行时,这工作正常,我可以成功上传没有问题.但是它在部署时给了我这个错误,我尝试做同样的事情.

我猜测我的storageConnectionString在Web部署发布过程中被搞乱,但我不确定如何解决这个问题?

c# connection-string azure azure-blob-storage

21
推荐指数
4
解决办法
2万
查看次数

Microsoft.Azure.StorageException: 指定的资源名称包含无效字符

我正在创建 blob 存储以将文件从本地路径加载到云。使用我在门户上创建的存储帐户,我收到一个错误:Microsoft.Azure.Storage.StorageException:The specified resource name contains invalid characters. 这是我想要实现的代码下面的代码。它缺少什么?请指教

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Azure.Storage;
using System.IO;

namespace BlobStorageApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Azure Blob Storage - Net");
            Console.WriteLine();

            ProcessAsync().GetAwaiter().GetResult();
        }

        private static async Task ProcessAsync()
        {
            CloudStorageAccount storageAccount = null;
            CloudBlobContainer cloudBlobContainer = null;
            string sourceFile = null;
            string destinationFile = null;

            string storageConnectionString = "DefaultEndpointsProtocol=https;" +
                "AccountName=gcobanistorage;" +
                "AccountKey=****;" + …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-blob-storage

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

从Azure Blob获取最新文件

假设我json每天在blob存储中生成几个文件.我想要做的是在我的任何目录中修改最新的文件.所以我的blob中有这样的东西:

2016/01/02/test.json
2016/01/02/test2.json
2016/02/03/test.json
Run Code Online (Sandbox Code Playgroud)

我想得到2016/02/03/test.json.因此,一种方法是获取文件的完整路径并进行正则表达式检查以查找创建的最新目录,但如果josn每个目录中有多个文件,则这不起作用.有没有什么File.GetLastWriteTime比得到最新的修改文件?我正在使用这些代码获取所有文件btw:

public static CloudBlobContainer GetBlobContainer(string accountName, string accountKey, string containerName)
{
    CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
    // blob client
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    // container
    CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName);
    return blobContainer;
}

public static IEnumerable<IListBlobItem> GetBlobItems(CloudBlobContainer container)
{
    IEnumerable<IListBlobItem> items = container.ListBlobs(useFlatBlobListing: true);
    return items;
}

public static List<string> GetAllBlobFiles(IEnumerable<IListBlobItem> blobs)
{
    var listOfFileNames = new List<string>();

    foreach (var blob in blobs)
    {
        var blobFileName …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-storage-blobs azure-sdk-.net azure-blob-storage

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

如何使用 C# 中的 Azure.Storage.Blobs 从 Azure 存储 blob 获取 ByteArray 格式的文件

我需要使用新包 Azure.Storage.Blobs 从 Azure 存储中获取字节数组格式的文件。我无法找到在 C# 中执行此操作的方法。

public byte[] GetFileFromAzure()
{
byte[] filebytes; 
    BlobServiceClient blobServiceClient = new BlobServiceClient( "TestClient");
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("TestContainer");
BlobClient blobClient = containerClient.GetBlobClient("te.xlsx");
    if (blobClient.ExistsAsync().Result)
{
    var response = blobClient.DownloadAsync().Result;
    using (var streamReader = new StreamReader(response.Value.Content))
    {
        var line = streamReader.ReadToEnd();
        //No idea how to convert this to ByteArray
    }
}
return filebytes;
}
Run Code Online (Sandbox Code Playgroud)

知道如何实现获取存储在 Azure Blob 存储上的文件字节数组吗?

感谢帮助。

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

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

Blob代码下载比MS Azure Storage Explorer慢得多

我正在从大小为1GB的Blob存储中下载一个Blob。

如果我使用MS Azure存储资源管理器,则需要不到10分钟的时间(我的下行线路为20兆位)。

但是,当我使用代码时:

await blobRef.DownloadToFileAsync("D:\\temp\\data.mdf", FileMode.Create);
Run Code Online (Sandbox Code Playgroud)

(我还尝试过使用内存中的流)下载250MB(需要杀死一个磁盘)需要一个多小时。我已经多次进行了此测试,并且始终如一。

我还监视了网络流量。

  • 通过Storage Exlorer,向下的网络流量约为20Mbit
  • 通过代码,向下的网络流量约为1兆位

编辑:我仍在使用旧版本的Azure存储资源管理器(1.4.1)。但是我可以确认新版本也给出了相同的结果。

c# azure-storage-blobs azure-blob-storage

14
推荐指数
2
解决办法
296
查看次数

如何允许覆盖 ASP.NET Core 应用程序中的 blob?

用户可以在创建记录时上传图像,当您编辑该记录并尝试上传新图像时,会出现“此 blob 已存在”错误。有没有办法可以在我的应用程序中启用同名 blob 的覆盖?

这是我处理更新过程的代码。

值得注意的是,为了应用程序,我创建了图像的三个迭代,因此我包含了包含该信息的数组。

CarController.cs

private readonly int[] sizeArray = new int[] { 700, 350, 150 };

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Car car)
{
    if (ModelState.IsValid)
    {
        //Create the Car
                _carService.InsertCar(car);

                //Get the ID of the newly created car
                int id = car.Id;

                //Define the container name for Azure Storage
                string strContainerName = "uploads";                               

                //Blob Client
                BlobServiceClient blobServiceClient = new BlobServiceClient(accessKey);
                BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(strContainerName);

                //Iterate over the array of image sizes
                foreach (var imageSize in sizeArray) …
Run Code Online (Sandbox Code Playgroud)

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

14
推荐指数
2
解决办法
2万
查看次数

如何从 Azure databricks 在 Azure Blob 中创建空文件夹

我有一个场景,我想列出 Azure Blob 中目录内的所有文件夹。如果不存在文件夹,则创建一个具有特定名称的新文件夹。

我正在尝试使用 dbutils.fs.ls(path) 列出文件夹。

但上述命令的问题是,如果路径不存在,它就会失败,这对我来说是一个有效的场景。

如果我的程序第一次运行,路径将不存在,并且 dbutils.fs.ls 命令将失败。有什么方法可以从 Databricks 动态处理这种情况。

如果我可以在执行作业之前从 Databricks 在 Azure Blob 中创建一个空文件夹,它也对我有用。

我尝试从 databricks 笔记本运行以下命令

   %sh mkdir -p /mnt/<mountName>/path/folderName 
Run Code Online (Sandbox Code Playgroud)

这里命令成功运行,即使我在 Azure Blob 中的容器已安装,它也不会创建该文件夹。抱歉这么长的帖子。任何帮助深表感谢。提前致谢

azure azure-blob-storage databricks azure-databricks

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

如何模拟Azure.Storage.Blobs的BlobContainerClient()?

我需要一些为 Azure.Storage.Blobs 的 BlobContainerClient 创建 Mock 对象的示例以进行单元测试。如何为以下课程创建模拟?

 public sealed class BlobStorageProcessor
    {
        public BlobStorageProcessor(ILogger logger, BlobContainerClient containerClient)
        {
            this.logger = logger;
            this.containerClient = containerClient;
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# mocking azure azure-blob-storage

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