如何在不编写自己的程序的情况下将文件上传到Azure Blob存储?

46

我创建了一个Azure存储帐户。我有一个400兆字节的.zip文件,我想将其放入Blob存储中以供以后使用。

我如何在不编写代码的情况下完成这个任务?有没有相应的界面可以实现呢?

15个回答

37

免费工具:

  1. Visual Studio 2010 - 安装Azure工具,您可以在Server Explorer中找到blobs
  2. Cloud Berry Lab的CloudBerry Explorer for Azure Blob Storage
  3. ClumpsyLeaf CloudXplorer
  4. 来自CodePlex的Azure Storage Explorer (尝试版本4 beta)

曾经有一个名为Azure Blob Explorer的旧程序,但它已经无法与新的Azure SDK配合使用。

在这些工具中,我个人最喜欢CloudBerry Explorer。


2
+1 VS2012与Azure工具也具有此功能,更新您的答案可能是值得的。 - Rich O'Kelly
我刚刚检查了一下,虽然已经过了一段时间,但今天CloudXplorer可以显示blob属性,列出、创建和下载快照,甚至浏览许多容器文件的内容,例如zip和vhd。它非常适合这个目的,我在其他工具中也看不到这样的功能。 - John
Azure现在已经提供一个Azure CLI软件包 - 可以从https://azure.microsoft.com/en-in/documentation/articles/storage-azure-cli/进行下载 - 文档非常好,而且很好用! - shekhar
现在Azure已经有了一个用于此类文件操作的工具:Azure Storage Explorer,它拥有用户友好的GUI界面,并且使用Azure用户名和密码凭据登录非常容易(上面是最新版本的链接)。 - Orhan Celik

18

最简单的方法是使用Azure Storage PowerShell。它提供了许多命令来管理您的存储容器/块/表/队列。

对于您提到的情况,您可以使用Set-AzureStorageBlobContent命令将本地文件上传到Azure存储作为块Blob或页Blob。

Set-AzureStorageBlobContent -Container containerName -File .\filename -Blob blobname

详细信息请参见 http://msdn.microsoft.com/en-us/library/dn408487.aspx


1
谢谢@Yao!我认为你是唯一真正回答了这个问题的人! - Eric Falsken
1
在我看来,这是最好的解决方案。为使其工作,您必须提供凭据,如此处所述:https://dev59.com/EXbZa4cB1Zd3GeqPKNTz#18806356 - kapex

12

6

StorageClient已经内置了此功能,无需编写任何内容:

var account = new CloudStorageAccount(creds, false);

var client = account.CreateCloudBlobClient();

var blob = client.GetBlobReference("/somecontainer/hugefile.zip");

//1MB seems to be a pretty good all purpose size
client.WriteBlockSizeInBytes = 1024;

//this sets # of parallel uploads for blocks
client.ParallelOperationThreadCount = 4; //normally set to one per CPU core

//this will break blobs up automatically after this size
client.SingleBlobUploadThresholdInBytes = 4096;

blob.UploadFile("somehugefile.zip");

1
哦,如果你正在寻找一个不错的免费程序,可以试试ClumsyLeaf CloudXplorer。它运行良好。 - dunnry
该评论实际上是 Ryan 的答案。OP 似乎正在寻找一个 GU<Interface> 接口。 - IUnknown

4

4

我使用Cyberduck来管理我的blob存储。

它是免费的,非常易于使用。 它也可以与其他云存储解决方案一起使用。

我最近还发现了这个:CloudXplorer

希望能有所帮助。


3
Cyberduck 不再支持 Azure。 - Marcom
1
Cyberduck现在再次支持Azure!http://betanews.com/2014/07/23/cyberduck-restores-windows-azure-support-adds-new-sshsftp-protocol-implementation/ - CodeThug

2
您可以使用Cloud Combine将文件可靠快速地上传到Azure Blob存储。

2

您可以使用命令提示符将文件上传到Azure存储帐户Blob。

安装Microsoft Azure Storage工具

然后使用CLI命令将其上传到您的帐户blob:

AzCopy /Source:"filepath" /Dest:bloburl /DestKey:accesskey /destType:blob

希望能帮到您.. :)

2
一个使用微软的 AzCopy 工具的简单批处理文件就可以解决问题了。您可以将文件拖放到以下批处理文件中,以上传到您的 Blob 存储容器中:

upload.bat

@ECHO OFF

SET BLOB_URL=https://<<<account name>>>.blob.core.windows.net/<<<container name>>>
SET BLOB_KEY=<<<your access key>>>

:AGAIN
IF "%~1" == "" GOTO DONE

AzCopy /Source:"%~d1%~p1" /Dest:%BLOB_URL% /DestKey:%BLOB_KEY% /Pattern:"%~n1%~x1" /destType:blob

SHIFT
GOTO AGAIN

:DONE
PAUSE

请注意,上述技术仅单独上传一个或多个文件(因为指定了Pattern标志),而不是上传整个目录。

1

您可以使用HTTP PUT动词将大型文件直接上传到Azure Blob Storage,下面的代码是我尝试过的最大文件大小为4.6 GB。您可以使用以下C#代码完成此操作:

// write up to ChunkSize of data to the web request
void WriteToStreamCallback(IAsyncResult asynchronousResult)
{
    var webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
    var requestStream = webRequest.EndGetRequestStream(asynchronousResult);
    var buffer = new Byte[4096];
    int bytesRead;
    var tempTotal = 0;

    File.FileStream.Position = DataSent;

    while ((bytesRead = File.FileStream.Read(buffer, 0, buffer.Length)) != 0
        && tempTotal + bytesRead < CHUNK_SIZE 
        && !File.IsDeleted 
        && File.State != Constants.FileStates.Error)
    {
        requestStream.Write(buffer, 0, bytesRead);
        requestStream.Flush();

        DataSent += bytesRead;
        tempTotal += bytesRead;

        File.UiDispatcher.BeginInvoke(OnProgressChanged);
    }

    requestStream.Close();

    if (!AbortRequested) webRequest.BeginGetResponse(ReadHttpResponseCallback, webRequest);
}

void StartUpload()
{
    var uriBuilder = new UriBuilder(UploadUrl);

    if (UseBlocks)
    {
        // encode the block name and add it to the query string
        CurrentBlockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
        uriBuilder.Query = uriBuilder.Query.TrimStart('?') + string.Format("&comp=block&blockid={0}", CurrentBlockId);
    }

    // with or without using blocks, we'll make a PUT request with the data
    var webRequest = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(uriBuilder.Uri);
    webRequest.Method = "PUT";
    webRequest.BeginGetRequestStream(WriteToStreamCallback, webRequest);
}

UploadUrl是由Azure自动生成的,其中包含一个共享访问签名。这个SAS URL指定了要上传Blob的位置以及授予安全访问(在您的情况下为写入访问)的时间长度。您可以像这样生成SAS URL:

readonly CloudBlobClient BlobClient;
readonly CloudBlobContainer BlobContainer;

public UploadService()
{
    // Setup the connection to Windows Azure Storage
    var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
    BlobClient = storageAccount.CreateCloudBlobClient();

    // Get and create the container
    BlobContainer = BlobClient.GetContainerReference("publicfiles");
}

string JsonSerializeData(string url)
{
    var serializer = new DataContractJsonSerializer(url.GetType());
    var memoryStream = new MemoryStream();

    serializer.WriteObject(memoryStream, url);

    return Encoding.Default.GetString(memoryStream.ToArray());
}

public string GetUploadUrl()
{
    var sasWithIdentifier = BlobContainer.GetSharedAccessSignature(new SharedAccessPolicy
    {
        Permissions = SharedAccessPermissions.Write,
        SharedAccessExpiryTime =
            DateTime.UtcNow.AddMinutes(60)
    });
    return JsonSerializeData(BlobContainer.Uri.AbsoluteUri + "/" + Guid.NewGuid() + sasWithIdentifier);
}

我在这个主题上也有一个帖子,你可以在这里找到更多信息 如何从网页上传大文件到Azure Blob


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接