交付和使用Azure REST-API SharedKey进行Blob上传 [英] Delivering and using an Azure REST-API SharedKey for Blob Upload

查看:56
本文介绍了交付和使用Azure REST-API SharedKey进行Blob上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前使用REST API(基于Microsoft示例)从.NET客户端配置文件计算机逐块上传blob. REST API示例直接使用Azure存储帐户名称和访问密钥在请求标头中构造SharedKey条目.对于生产代码,我们需要在服务器上计算SharedKey,并将其交付给客户端以供会话期间使用.

We currently use the REST API (based on microsoft samples) to upload blobs blockwise from a .NET client profile machine. The REST API examples use the Azure storage account name and access key directly to construct the SharedKey entry in the request header. For production code, we'll need to calculate the SharedKey on our server, and deliver it for the client to use during the session.

为Blob创建SharedKey的示例为我提供了一个URL加包含访问参数的查询字符串.

Examples of SharedKey creation for blobs provide me with a Url plus query string that contains the access parameters.

我的问题:如何使该Url/查询字符串键格式与Azure REST API所需的SharedKey标头条目一起使用?

My question: How do I get this Url/query string key format work in conjunction with the SharedKey header entry required by the Azure REST API?

任何指针或技巧都将不胜感激! R

Any pointers or tips greatly appreciated! R

推荐答案

在这里.显然,可以对该代码进行很多改进:)尝试一下.让我知道它是否适合您.我可以使用以下代码在开发存储中上传Blob:

Here you go. Obviously a lot of improvement can be made to this code :) Give it a try. Do let me know if it works for you. I was able to upload a blob in development storage using the code below:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections.Specialized;
using System.Globalization;

namespace UploadBlobUsingSASUrl { class Program { //This is part of SAS signature (query string). We will construct the URI later using this. private static string sasSignature = "sr=c&st=2012-08-16T14%3A38%3A48Z&se=2012-08-16T15%3A38%3A48Z&sp=w&sig=aNTLYQtwA1UmjG7j8Lg44t8YThL16FkNYBi54kl4ZKo%3D"; //Blob storage endpoint private static string blobStorageEndpoint = "http://127.0.0.1:10000/devstoreaccount1"; //Blob container name private static string blobContainerName = "[blob container name. SAS URI with Write permission must be created on this blob container]"; //File to upload private static string fileToUpload = @"[Full path of the file you wish to upload]"; //This is the default block size (This application always assumes that a file will be split in blocks and then uploaded). private static int blockSize = 256 * 1024;//256 KB //Storage service version (Unless you're using latest SAS related changes in cloud storage, use this version). For development storage always use this version. private static string x_ms_version = "2011-08-18"; //Template for put block list private static string blockListTemplate = @"{0}"; // Template for block id (to be included in put block list template) private static string blockIdTemplate = "{0}"; //We'll keep a list of block ids. private static List blockIds = new List(); static void Main(string[] args) {

namespace UploadBlobUsingSASUrl { class Program { //This is part of SAS signature (query string). We will construct the URI later using this. private static string sasSignature = "sr=c&st=2012-08-16T14%3A38%3A48Z&se=2012-08-16T15%3A38%3A48Z&sp=w&sig=aNTLYQtwA1UmjG7j8Lg44t8YThL16FkNYBi54kl4ZKo%3D"; //Blob storage endpoint private static string blobStorageEndpoint = "http://127.0.0.1:10000/devstoreaccount1"; //Blob container name private static string blobContainerName = "[blob container name. SAS URI with Write permission must be created on this blob container]"; //File to upload private static string fileToUpload = @"[Full path of the file you wish to upload]"; //This is the default block size (This application always assumes that a file will be split in blocks and then uploaded). private static int blockSize = 256 * 1024;//256 KB //Storage service version (Unless you're using latest SAS related changes in cloud storage, use this version). For development storage always use this version. private static string x_ms_version = "2011-08-18"; //Template for put block list private static string blockListTemplate = @"{0}"; // Template for block id (to be included in put block list template) private static string blockIdTemplate = "{0}"; //We'll keep a list of block ids. private static List blockIds = new List(); static void Main(string[] args) {

}

这篇关于交付和使用Azure REST-API SharedKey进行Blob上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆