本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions类的典型用法代码示例。如果您正苦于以下问题:C# BlobContainerPermissions类的具体用法?C# BlobContainerPermissions怎么用?C# BlobContainerPermissions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlobContainerPermissions类属于Microsoft.WindowsAzure.Storage.Blob命名空间,在下文中一共展示了BlobContainerPermissions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlobContainer
public BlobContainer(string name)
{
// hämta connectionsträngen från config // RoleEnviroment bestämmer settingvalue runtime
//var connectionString = RoleEnvironment.GetConfigurationSettingValue("PhotoAppStorage");
//var connectionString = CloudConfigurationManager.GetSetting("CloudStorageApp");
// hämtar kontot utfrån connectionsträngens värde
//var account = CloudStorageAccount.Parse(connectionString);
//var account = CloudStorageAccount.DevelopmentStorageAccount;
var cred = new StorageCredentials("jholm",
"/bVipQ2JxjWwYrZQfHmzhaBx1p1s8BoD/wX6VWOmg4/gpVo/aALrjsDUKqzXsFtc9utepPqe65NposrXt9YsyA==");
var account = new CloudStorageAccount(cred, true);
// skapar en blobclient
_client = account.CreateCloudBlobClient();
m_BlobContainer = _client.GetContainerReference(name);
// Om det inte finns någon container med det namnet
if (!m_BlobContainer.Exists())
{
// Skapa containern
m_BlobContainer.Create();
var permissions = new BlobContainerPermissions()
{
PublicAccess = BlobContainerPublicAccessType.Blob
};
// Sätter public access till blobs
m_BlobContainer.SetPermissions(permissions);
}
}
示例2: Get
public string Get()
{
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(Constants.ConfigurationKeys.StorageConnection));
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(CloudConfigurationManager.GetSetting(Constants.ConfigurationKeys.ContainerName));
container.CreateIfNotExists();
var blobPermissions = new BlobContainerPermissions();
blobPermissions.SharedAccessPolicies.Add(AppPolicyName, new SharedAccessBlobPolicy()
{
// To ensure SAS is valid immediately, don’t set start time.
// This way, you can avoid failures caused by small clock differences.
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5),
Permissions = SharedAccessBlobPermissions.Write |
SharedAccessBlobPermissions.Read
});
blobPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(blobPermissions);
var sasToken = container.GetSharedAccessSignature(new SharedAccessBlobPolicy(), AppPolicyName);
return container.Uri + sasToken;
}
示例3: SetContainerAcl
/// <summary>
/// set the access level of specified container
/// </summary>
/// <param name="name">container name</param>
/// <param name="accessLevel">access level in ("off", "blob", "container")</param>
internal void SetContainerAcl(string name, BlobContainerPublicAccessType accessLevel)
{
if (!NameUtil.IsValidContainerName(name))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, name));
}
BlobContainerPermissions permissions = new BlobContainerPermissions();
permissions.PublicAccess = accessLevel;
BlobRequestOptions requestOptions = RequestOptions;
AccessCondition accessCondition = null;
CloudBlobContainer container = Channel.GetContainerReference(name);
if (!Channel.DoesContainerExist(container, requestOptions, OperationContext))
{
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
}
Channel.SetContainerPermissions(container, permissions, accessCondition, requestOptions, OperationContext);
AzureStorageContainer azureContainer = new AzureStorageContainer(container, permissions);
if (PassThru)
{
WriteObjectWithStorageContext(azureContainer);
}
}
示例4: SetContainerAcl
/// <summary>
/// set the access level of specified container
/// </summary>
/// <param name="name">container name</param>
/// <param name="accessLevel">access level in ("off", "blob", "container")</param>
internal async Task SetContainerAcl(long taskId, IStorageBlobManagement localChannel, string name, BlobContainerPublicAccessType accessLevel)
{
if (!NameUtil.IsValidContainerName(name))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, name));
}
BlobContainerPermissions permissions = new BlobContainerPermissions();
permissions.PublicAccess = accessLevel;
BlobRequestOptions requestOptions = RequestOptions;
AccessCondition accessCondition = null;
CloudBlobContainer container = localChannel.GetContainerReference(name);
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
{
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
}
await localChannel.SetContainerPermissionsAsync(container, permissions, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
if (PassThru)
{
WriteCloudContainerObject(taskId, localChannel, container, permissions);
}
}
示例5: Upload
static public void Upload(string filepath, string blobname, string accountName, string accountKey)
{
try
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer sampleContainer = client.GetContainerReference("public-samples");
sampleContainer.CreateIfNotExists();
// for public access ////
BlobContainerPermissions permissions = new BlobContainerPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
sampleContainer.SetPermissions(permissions);
/////////////////////////
CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(blobname);
using (Stream file = File.OpenRead(filepath))
{
blob.UploadFromStream(file);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
示例6: Post
public GetUploadLocationResponse Post(GetUploadLocationRequest request)
{
_log.StartLog(request);
try
{
var contName = "deletable" + Guid.NewGuid().ToString("D").ToLowerInvariant();
var container = _azure.CreateContainerIfDoesNotExist(contName);
var blobPolicy = new SharedAccessBlobPolicy {
Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List,
SharedAccessExpiryTime = DateTimeOffset.Now.AddHours(HOURS_FILE_SHOULD_BE_ACCESSIBLE)
};
var permissions = new BlobContainerPermissions();
permissions.SharedAccessPolicies.Add("mypolicy", blobPolicy);
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
var sharedAccessSignature = container.GetSharedAccessSignature("mypolicy");
return new GetUploadLocationResponse {Name= container.Name, Location = container.Uri.ToString(), Sas = sharedAccessSignature, Account = _azure.Account};
}
catch (Exception e)
{
_log.Fatal("error", e);
Errors.Add(e.Message + " " + e.StackTrace);
return new GetUploadLocationResponse {Errors = Errors};
}
}
示例7: GetBlobContainer
/// <summary>
/// Function to get Blob container
/// </summary>
/// <param name="containerName">container to look</param>
/// <returns>Blob container</returns>
public CloudBlobContainer GetBlobContainer()
{
// get the container reference
var blobContainer = blobClient.GetContainerReference(containerName);
try
{
// Create the container if it does not exist.
var options = new BlobRequestOptions
{
MaximumExecutionTime = TimeSpan.FromSeconds(2),
};
if (blobContainer.CreateIfNotExists())
{
// Set permissions on the container, if it was created.
var containerPermissions = new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Off
};
blobContainer.SetPermissions(containerPermissions);
}
}
catch (Exception ex)
{
}
return blobContainer;
}
示例8: DeleteFile
public static bool DeleteFile(string accountName, string accountKey, string containerName, string fileName, bool delSubDirs)
{
try
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=" + accountName + ";AccountKey=" + accountKey);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(containerPermissions);
if (false == delSubDirs)
{
CloudBlockBlob remoteFile = container.GetBlockBlobReference(fileName);
remoteFile.DeleteIfExists();
}
if (true == delSubDirs)
{
foreach (IListBlobItem item in container.ListBlobs(fileName, true))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blob.DeleteIfExists();
}
}
}
catch (Exception)
{
return false;
}
return true;
}
示例9: CopyBlobData
/// <summary>
/// Initiates the SolCat Azure blob data sync.
/// </summary>
public static void CopyBlobData()
{
// Authentication Credentials for Azure Storage:
var credsSrc
= new StorageCredentials(
ConfigHelper.GetConfigValue("HubContainerName"),
ConfigHelper.GetConfigValue("HubContainerKey"));
var credsDest
= new StorageCredentials(
ConfigHelper.GetConfigValue("NodeContainerKey"),
ConfigHelper.GetConfigValue("NodeContainerKey"));
// Source Container: Hub (Development)
_srcContainer =
new CloudBlobContainer(
new Uri(ConfigHelper.GetConfigValue("HubContainerUri")),
credsSrc);
// Destination Container: Node (Production)
_destContainer =
new CloudBlobContainer(
new Uri(ConfigHelper.GetConfigValue("NodeContainerUri")),
credsDest);
// Set permissions on the container:
var permissions = new BlobContainerPermissions {PublicAccess = BlobContainerPublicAccessType.Blob};
_srcContainer.SetPermissions(permissions);
_destContainer.SetPermissions(permissions);
// Call the blob copy master method:
CopyBlobs(_srcContainer, _destContainer);
}
示例10: 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);
}
}
示例11: azureStorageHelper
public azureStorageHelper(string acountName, string accountKey)
{
sCredentials = new StorageCredentials(acountName, accountKey);
storageAccount = new CloudStorageAccount(sCredentials, true);
queueClient = storageAccount.CreateCloudQueueClient();
blobClient = storageAccount.CreateCloudBlobClient();
permisions = new BlobContainerPermissions();
permisions.PublicAccess = BlobContainerPublicAccessType.Container;
}
示例12: SaveBinaryToAzureStorage
public static async Task<string> SaveBinaryToAzureStorage(MobileAppSettingsDictionary settings, string blobId, string blobData )
{
string storageAccountName;
string storageAccountKey;
// Try to get the Azure storage account token from app settings.
if (!(settings.TryGetValue("STORAGE_ACCOUNT_NAME", out storageAccountName) |
settings.TryGetValue("STORAGE_ACCOUNT_ACCESS_KEY", out storageAccountKey)))
{
return string.Empty;
}
// Set the URI for the Blob Storage service.
Uri blobEndpoint = new Uri(string.Format("https://{0}.blob.core.windows.net", storageAccountName));
// Create the BLOB service client.
CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint,
new StorageCredentials(storageAccountName, storageAccountKey));
string ContainerName = "beerdrinkinimages";
// Create a container, if it doesn't already exist.
CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);
await container.CreateIfNotExistsAsync();
// Create a shared access permission policy.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// Enable anonymous read access to BLOBs.
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(containerPermissions);
// Define a policy that gives write access to the container for 1 minute.
SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy()
{
SharedAccessStartTime = DateTime.UtcNow,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1),
Permissions = SharedAccessBlobPermissions.Write
};
// Get the SAS as a string.
var SasQueryString = container.GetSharedAccessSignature(sasPolicy);
// Set the URL used to store the image.
var avatarUri = string.Format("{0}{1}/{2}", blobEndpoint.ToString(),
ContainerName, blobId.ToLower());
// Upload the new image as a BLOB from the string.
CloudBlockBlob blobFromSASCredential =
container.GetBlockBlobReference(blobId.ToLower());
blobFromSASCredential.UploadTextAsync(blobData);
return avatarUri;
}
示例13: SetupEnvironment
public void SetupEnvironment()
{
var blobClient = _acct.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(POST_FILE_CONTAINER);
container.CreateIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(containerPermissions);
}
示例14: AssignDownloadPolicyContainerPermissions
/// <summary>
/// Assign permissions for a download to occur for our readonly permission policy
/// </summary>
static void AssignDownloadPolicyContainerPermissions(CloudBlobContainer container)
{
// Secure storage. We will provide read tokens for access to blob data on a per-blob basis.
var containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
containerPermissions.SharedAccessPolicies.Add(DownloadPolicyName, new SharedAccessBlobPolicy
{
Permissions = SharedAccessBlobPermissions.Read
});
container.SetPermissions(containerPermissions);
}
示例15: CreateBlobs
public void CreateBlobs(bool createSettingsBlob, bool createModelBlob, int modelId = 1)
{
if (createSettingsBlob || createModelBlob)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(MockCommandCenter.StorageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
var localContainer = blobClient.GetContainerReference(this.localAzureContainerName);
localContainer.CreateIfNotExists();
if (createSettingsBlob)
{
var settingsBlob = localContainer.GetBlockBlobReference(this.localAzureSettingsBlobName);
byte[] settingsContent = this.GetSettingsBlobContent();
settingsBlob.UploadFromByteArray(settingsContent, 0, settingsContent.Length);
this.localAzureSettingsBlobUri = settingsBlob.Uri.ToString();
}
if (createModelBlob)
{
var modelBlob = localContainer.GetBlockBlobReference(this.localAzureModelBlobName);
byte[] modelContent = this.GetCBModelBlobContent(modelId);
modelBlob.UploadFromByteArray(modelContent, 0, modelContent.Length);
this.localAzureModelBlobUri = modelBlob.Uri.ToString();
}
var locationContainer = blobClient.GetContainerReference(this.localAzureBlobLocationContainerName);
locationContainer.CreateIfNotExists();
var publicAccessPermission = new BlobContainerPermissions()
{
PublicAccess = BlobContainerPublicAccessType.Blob
};
locationContainer.SetPermissions(publicAccessPermission);
var metadata = new ApplicationTransferMetadata
{
ApplicationID = "test",
ConnectionString = MockCommandCenter.StorageConnectionString,
ExperimentalUnitDuration = 15,
IsExplorationEnabled = true,
ModelBlobUri = this.localAzureModelBlobUri,
SettingsBlobUri = this.localAzureSettingsBlobUri,
ModelId = "latest"
};
var locationBlob = locationContainer.GetBlockBlobReference(this.token);
byte[] locationBlobContent = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(metadata));
locationBlob.UploadFromByteArray(locationBlobContent, 0, locationBlobContent.Length);
}
}