本文整理汇总了C#中Microsoft.WindowsAzure.Storage.CloudStorageAccount.CreateCloudBlobClient方法的典型用法代码示例。如果您正苦于以下问题:C# CloudStorageAccount.CreateCloudBlobClient方法的具体用法?C# CloudStorageAccount.CreateCloudBlobClient怎么用?C# CloudStorageAccount.CreateCloudBlobClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.CreateCloudBlobClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContainerReference
private CloudBlobContainer GetContainerReference(string storageName, string storageKey, string containerName)
{
var credentials = new StorageCredentials(storageName, storageKey);
var account = new CloudStorageAccount(credentials, true);
var blobClient = account.CreateCloudBlobClient();
return blobClient.GetContainerReference(containerName);
}
示例2: Post
public bool Post(CommitBlobRequest commitRequest)
{
var result = false;
commitRequest.FileName = commitRequest.FileName.ToLower();
commitRequest.ContainerName = commitRequest.ContainerName.ToLower();
var accountAndKey = new StorageCredentials(AppSettings.StorageAccountName, AppSettings.StorageAccountKey);
var storageaccount = new CloudStorageAccount(accountAndKey, true);
var blobClient = storageaccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(commitRequest.ContainerName);
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
CloudBlockBlob blob = container.GetBlockBlobReference(commitRequest.FileName);
try
{
blob.PutBlockList(commitRequest.blobParts);
blob.Properties.ContentType = commitRequest.type;
blob.Properties.ContentDisposition = "attachment";
blob.SetProperties();
result = true;
}
catch (Exception ex)
{
//Trace.TraceError("BuildFileSasUrl throw excaption", ex.Message);
}
return result;
}
示例3: InitStorage
private static void InitStorage()
{
var credentials = new StorageCredentials(AppKeys.Storage_Account_Name, AppKeys.PrimaryAccessKey);
var storageAccount = new CloudStorageAccount(credentials, true);
var blobClient = storageAccount.CreateCloudBlobClient();
imagesContainer = blobClient.GetContainerReference("images");
}
示例4: downloadSong
public bool downloadSong(int song_id, string song_name, string song_path)
{
bool flag = false;
//hace la cuenta
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
//crea el cliente
CloudBlobClient client = account.CreateCloudBlobClient();
//crae el contenedor
CloudBlobContainer sampleContainer = client.GetContainerReference("music");
CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(song_id.ToString() + ".mp3");
try
{
//FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\\Users\\Andres\\Music");
Console.WriteLine("Path: {0}", song_path + "\\" + song_name);
Stream outputFile = new FileStream(song_path + "\\" + song_name, FileMode.Create);
blob.DownloadToStream(outputFile);
flag = true;
}
catch (Exception e)
{
Console.WriteLine(e);
flag = false;
}
return flag;
}
示例5: Initialise
/// <summary>
/// Occurs when a storage provider operation has completed.
/// </summary>
//public event EventHandler<StorageProviderEventArgs> StorageProviderOperationCompleted;
#endregion
// Initialiser method
private void Initialise(string storageAccount, string containerName)
{
if (String.IsNullOrEmpty(containerName))
throw new ArgumentException("You must provide the base Container Name", "containerName");
ContainerName = containerName;
_account = CloudStorageAccount.Parse(storageAccount);
_blobClient = _account.CreateCloudBlobClient();
_container = _blobClient.GetContainerReference(ContainerName);
try
{
_container.FetchAttributes();
}
catch (StorageException)
{
Trace.WriteLine(string.Format("Create new container: {0}", ContainerName), "Information");
_container.Create();
// set new container's permissions
// Create a permission policy to set the public access setting for the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// The public access setting explicitly specifies that the container is private,
// so that it can't be accessed anonymously.
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
//Set the permission policy on the container.
_container.SetPermissions(containerPermissions);
}
}
示例6: Upload
public Uri Upload(SubscriptionCloudCredentials credentials, string storageAccountName, string packageFile, string uploadedFileName)
{
var cloudStorage =
new CloudStorageAccount(new StorageCredentials(storageAccountName, GetStorageAccountPrimaryKey(credentials, storageAccountName)), true);
var blobClient = cloudStorage.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(OctopusPackagesContainerName);
container.CreateIfNotExists();
var permission = container.GetPermissions();
permission.PublicAccess = BlobContainerPublicAccessType.Off;
container.SetPermissions(permission);
var fileInfo = new FileInfo(packageFile);
var packageBlob = GetUniqueBlobName(uploadedFileName, fileInfo, container);
if (packageBlob.Exists())
{
Log.VerboseFormat("A blob named {0} already exists with the same length, so it will be used instead of uploading the new package.",
packageBlob.Name);
return packageBlob.Uri;
}
UploadBlobInChunks(fileInfo, packageBlob, blobClient);
Log.Info("Package upload complete");
return packageBlob.Uri;
}
示例7: AzureBlobStorageProvider
public AzureBlobStorageProvider(CloudStorageAccount storageAccount)
{
_storageAccount = storageAccount;
BlobClient = _storageAccount.CreateCloudBlobClient();
Containers = new List<CloudBlobContainer>();
ContainerFactory = CreateContainer;
}
示例8: WriteAuditRecord
public async Task WriteAuditRecord(string resourceType, CloudStorageAccount storageAccount)
{
var entry = new AuditEntry(
this,
await AuditActor.GetCurrentMachineActor());
// Write the blob to the storage account
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("auditing");
await container.CreateIfNotExistsAsync();
var blob = container.GetBlockBlobReference(
resourceType + "/" + this.GetPath() + "/" + DateTime.UtcNow.ToString("s") + "-" + this.GetAction().ToLowerInvariant() + ".audit.v1.json");
if (await blob.ExistsAsync())
{
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentCulture,
Strings.Package_DeleteCommand_AuditBlobExists,
blob.Uri.AbsoluteUri));
}
byte[] data = Encoding.UTF8.GetBytes(
JsonFormat.Serialize(entry));
await blob.UploadFromByteArrayAsync(data, 0, data.Length);
}
示例9: HomeController
public HomeController()
{
storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["StorageConnectionString"]);
tableClient = storageAccount.CreateCloudTableClient();
table = tableClient.GetTableReference("fouramigos");
table.CreateIfNotExists();
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference("fouramigos");
container.CreateIfNotExists();
BlobContainerPermissions permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
//lägga till nya
//var tablemodels = new TableModel("Brutus", "Uggla") { Location = "T4", Description="Uggla i träd", Type="Foto" };
//var tablemodels1 = new TableModel("brutus", "Örn") { Location = "T4", Description="Örn som flyger", Type = "Foto" };
//var opreation = TableOperation.Insert(tablemodels);
//var operation2 = TableOperation.Insert(tablemodels1);
//table.Execute(opreation);
//table.Execute(operation2);
}
示例10: configureCors
private static void configureCors(CloudStorageAccount storageAccount)
{
var blobClient = storageAccount.CreateCloudBlobClient();
Console.WriteLine("Storage Account: " + storageAccount.BlobEndpoint);
var newProperties = CurrentProperties(blobClient);
newProperties.DefaultServiceVersion = "2013-08-15";
blobClient.SetServiceProperties(newProperties);
var addRule = true;
if (addRule)
{
var ruleWideOpenWriter = new CorsRule()
{
AllowedHeaders = ALLOWED_CORS_HEADERS,
AllowedOrigins = ALLOWED_CORS_ORIGINS,
AllowedMethods = ALLOWED_CORS_METHODS,
MaxAgeInSeconds = (int)TimeSpan.FromDays(ALLOWED_CORS_AGE_DAYS).TotalSeconds
};
newProperties.Cors.CorsRules.Clear();
newProperties.Cors.CorsRules.Add(ruleWideOpenWriter);
blobClient.SetServiceProperties(newProperties);
Console.WriteLine("New Properties:");
CurrentProperties(blobClient);
Console.ReadLine();
}
}
示例11: GetRanking
private static IDictionary<string, int> GetRanking(CloudStorageAccount storageAccount, string blobName)
{
IDictionary<string, int> ranking = new Dictionary<string, int>();
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("ranking");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
MemoryStream stream = new MemoryStream();
blockBlob.DownloadToStream(stream);
stream.Seek(0, SeekOrigin.Begin);
using (TextReader textReader = new StreamReader(stream))
{
using (JsonReader jsonReader = new JsonTextReader(textReader))
{
JArray array = JArray.Load(jsonReader);
foreach (JObject item in array)
{
ranking.Add(item["id"].ToString(), item["rank"].ToObject<int>());
}
}
}
return ranking;
}
示例12: GetStorageClient
private CloudBlobClient GetStorageClient()
{
var accountName = StorageAccountName.Contains(".") ? StorageAccountName.Substring(0, StorageAccountName.IndexOf('.')) : StorageAccountName;
var storageCredentials = new StorageCredentials(accountName, StorageAccountKey);
var storageAccount = new CloudStorageAccount(storageCredentials, true);
return storageAccount.CreateCloudBlobClient();
}
示例13: BlobFileProvider
public BlobFileProvider(IEnumerable<string> locations)
: base()
{
_storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
_blobClient = _storageAccount.CreateCloudBlobClient();
_container = _blobClient.GetContainerReference("data");
_container.CreateIfNotExists();
_strings = new List<string>();
foreach(string location in locations) {
foreach (IListBlobItem item in _container.ListBlobs(location,true))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
string text;
using (var memoryStream = new MemoryStream())
{
blob.DownloadToStream(memoryStream);
text = Encoding.UTF8.GetString(memoryStream.ToArray());
if (text[0] == _byteOrderMarkUtf8[0])
{
text= text.Remove(0,_byteOrderMarkUtf8.Length);
}
_strings.Add(text);
}
}
}
}
}
示例14: ValidateAccountAccessible
public static bool ValidateAccountAccessible(CloudStorageAccount account)
{
if (account == null)
{
throw new ArgumentNullException("account");
}
// Verify the credentials are correct.
// Have to actually ping a storage operation.
var client = account.CreateCloudBlobClient();
try
{
// This can hang for a long time if the account name is wrong.
// If will fail fast if the password is incorrect.
client.GetServiceProperties();
}
catch (OperationCanceledException)
{
throw;
}
catch
{
return false;
}
return true;
}
示例15: BlobManager
public BlobManager(){
try
{
storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference("supstorage");
container.CreateIfNotExists();
}
catch (ArgumentNullException)
{
Trace.TraceInformation("CloudStorageAccount Exception null ou vide");
// Use Application Local Storage Account String
}
catch (NullReferenceException)
{
Trace.TraceInformation("CloudBlobClient Or CloudBlobContainer Exception");
// Create Container
}
catch (FormatException)
{
Trace.TraceInformation("CloudStorageAccount Exception Connection String Invalid");
}
catch (ArgumentException)
{
Trace.TraceInformation("CloudStorageAccount Exception connectionString ne peut pas être analysée");
}
}