本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.GetBlockBlobReference方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.GetBlockBlobReference方法的具体用法?C# CloudBlobContainer.GetBlockBlobReference怎么用?C# CloudBlobContainer.GetBlockBlobReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.GetBlockBlobReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadPdfToBlob
/// <summary>
/// Upload the generated receipt Pdf to Blob storage.
/// </summary>
/// <param name="file">Byte array containig the Pdf file contents to be uploaded.</param>
/// <param name="fileName">The desired filename of the uploaded file.</param>
/// <returns></returns>
public string UploadPdfToBlob(byte[] file, string fileName)
{
// Create the blob client.
blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
blobContainer = blobClient.GetContainerReference(receiptBlobName);
// Create the container if it doesn't already exist.
blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
string fileUri = string.Empty;
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileName);
using (var stream = new MemoryStream(file))
{
// Upload the in-memory Pdf file to blob storage.
blockBlob.UploadFromStream(stream);
}
fileUri = blockBlob.Uri.ToString();
return fileUri;
}
示例2: ParallelUploadFile
public static void ParallelUploadFile(CloudBlobContainer blobContainer, string blobName, string filePath, string contentType = null)
{
var start = DateTime.Now;
Console.WriteLine("\nUpload file in parallel.");
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(blobName);
// 2M blocks for demo
int blockLength = 2 * 1000 * 1024;
byte[] dataToUpload = File.ReadAllBytes(filePath);
int numberOfBlocks = (dataToUpload.Length / blockLength) + 1;
string[] blockIds = new string[numberOfBlocks];
Parallel.For(0, numberOfBlocks, x =>
{
var blockId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
var currentLength = Math.Min(blockLength, dataToUpload.Length - (x * blockLength));
using (var memStream = new MemoryStream(dataToUpload, x * blockLength, currentLength))
{
blockBlob.PutBlock(blockId, memStream, null);
}
blockIds[x] = blockId;
Console.WriteLine("BlockId:{0}", blockId);
});
if (!String.IsNullOrEmpty(contentType)) { blockBlob.Properties.ContentType = contentType; }
blockBlob.PutBlockList(blockIds);
Console.WriteLine("URL:{0}, ETag:{1}", blockBlob.Uri, blockBlob.Properties.ETag);
var timespan = DateTime.Now - start;
Console.WriteLine("{0} seconds.", timespan.Seconds);
}
示例3: UploadFileToBlob
public static void UploadFileToBlob(string fileName, string containerSAS)
{
Console.WriteLine("Uploading {0} to {1}", fileName, containerSAS);
CloudBlobContainer container = new CloudBlobContainer(new Uri(containerSAS));
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
blob.UploadFromStream(new FileStream(fileName, FileMode.Open, FileAccess.Read));
}
示例4: BlobFile
/// <summary>
/// Initializes a new instance of the <see cref="BlobFile" /> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="address">The address.</param>
/// <exception cref="ArgumentOutOfRangeException"/>
/// <exception cref="ArgumentNullException"/>
public BlobFile(BlobFileSystem fileSystem, INodeAddress address)
: base(address, fileSystem)
{
_blobContainer = fileSystem.BlobClient.GetContainerReference(address.PathToDepth(1).Substring(1));
_path = string.Join("/", Address.AbsolutePath.Split('/').Where((item, index) => index > 1));
_blockBlob = _blobContainer.GetBlockBlobReference(_path);
}
示例5: CreateBlobs
public static List<string> CreateBlobs(CloudBlobContainer container, int count, BlobType type)
{
string name;
List<string> blobs = new List<string>();
for (int i = 0; i < count; i++)
{
switch (type)
{
case BlobType.BlockBlob:
name = "bb" + Guid.NewGuid().ToString();
CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
blockBlob.PutBlockList(new string[] { });
blobs.Add(name);
break;
case BlobType.PageBlob:
name = "pb" + Guid.NewGuid().ToString();
CloudPageBlob pageBlob = container.GetPageBlobReference(name);
pageBlob.Create(0);
blobs.Add(name);
break;
}
}
return blobs;
}
示例6: GetBlob
private CloudBlockBlob GetBlob(string path, CloudBlobContainer container = null)
{
container = container ?? GetContainer(path);
var blobName = GetBlobName(path);
var blob = container.GetBlockBlobReference(blobName);
return blob;
}
示例7: ConfigurationFile
public ConfigurationFile(CloudBlobContainer DeploymentContainer, string file)
{
//var config = DeploymentContainer.GetDirectoryReference("Configuration");
init(DeploymentContainer.GetBlockBlobReference(file));
//
}
示例8: CreateLogs
public static List<string> CreateLogs(CloudBlobContainer container, StorageService service, int count, DateTime start, string granularity)
{
string name;
List<string> blobs = new List<string>();
for (int i = 0; i < count; i++)
{
CloudBlockBlob blockBlob;
switch (granularity)
{
case "hour":
name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddHours(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log");
break;
case "day":
name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddDays(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log");
break;
case "month":
name = string.Concat(service.ToString().ToLowerInvariant(), "/", start.AddMonths(i).ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture), "00/000001.log");
break;
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "CreateLogs granularity of '{0}' is invalid.", granularity));
}
blockBlob = container.GetBlockBlobReference(name);
blockBlob.PutBlockList(new string[] { });
blobs.Add(name);
}
return blobs;
}
示例9: Main
static void Main(string[] args)
{
string sas = "https://jamborstorage.blob.core.windows.net/sascontainer?sv=2014-02-14&sr=c&sig=HaD3DPQYd%2FQMJnuvYRafx0NuQQWSm0ZelODLxbyjEWI%3D&se=2014-09-03T09%3A43%3A28Z&sp=wl";
CloudBlobContainer container = new CloudBlobContainer(new Uri(sas));
//Create a list to store blob URIs returned by a listing operation on the container.
List<Uri> blobUris = new List<Uri>();
try
{
//Write operation: write a new blob to the container.
CloudBlockBlob blob = container.GetBlockBlobReference("blobCreatedViaSAS.txt");
string blobContent = "This blob was created with a shared access signature granting write permissions to the container. ";
MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
msWrite.Position = 0;
using (msWrite)
{
blob.UploadFromStream(msWrite);
}
Console.WriteLine("Write operation succeeded for SAS " + sas);
Console.WriteLine();
}
catch (StorageException e)
{
Console.WriteLine("Write operation failed for SAS " + sas);
Console.WriteLine("Additional error information: " + e.Message);
Console.WriteLine();
}
}
示例10: InsertTodoItem
private async Task InsertTodoItem(DataModel.TodoItem todoItem)
{
string errorString = string.Empty;
if (media != null)
{
todoItem.ContainerName = "todoitemimages";
todoItem.ResourceName = Guid.NewGuid().ToString();
}
await todoTable.InsertAsync(todoItem);
if (!string.IsNullOrEmpty(todoItem.SasQueryString))
{
StorageCredentials cred = new StorageCredentials(todoItem.SasQueryString);
var imageUri = new Uri(todoItem.ImageUri);
CloudBlobContainer container = new CloudBlobContainer(
new Uri(string.Format("https://{0}/{1}",
imageUri.Host, todoItem.ContainerName)), cred);
using (var inputStream = await media.OpenReadAsync())
{
CloudBlockBlob blobFromSASCredential =
container.GetBlockBlobReference(todoItem.ResourceName);
await blobFromSASCredential.UploadFromStreamAsync(inputStream);
}
await ResetCaptureAsync();
}
items.Add(todoItem);
}
示例11: CreateBlobsAsync
public static async Task<List<string>> CreateBlobsAsync(CloudBlobContainer container, int count, BlobType type)
{
string name;
List<string> blobs = new List<string>();
for (int i = 0; i < count; i++)
{
switch (type)
{
case BlobType.BlockBlob:
name = "bb" + Guid.NewGuid().ToString();
CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
await blockBlob.PutBlockListAsync(new string[] { });
blobs.Add(name);
break;
case BlobType.PageBlob:
name = "pb" + Guid.NewGuid().ToString();
CloudPageBlob pageBlob = container.GetPageBlobReference(name);
await pageBlob.CreateAsync(0);
blobs.Add(name);
break;
case BlobType.AppendBlob:
name = "ab" + Guid.NewGuid().ToString();
CloudAppendBlob appendBlob = container.GetAppendBlobReference(name);
await appendBlob.CreateOrReplaceAsync();
blobs.Add(name);
break;
}
}
return blobs;
}
示例12: GetBlobSasUri
static string GetBlobSasUri(CloudBlobContainer container)
{
//Get a reference to a blob within the container.
CloudBlockBlob blob = container.GetBlockBlobReference("sasblob.txt");
//Upload text to the blob. If the blob does not yet exist, it will be created.
//If the blob does exist, its existing content will be overwritten.
string blobContent = "This blob will be accessible to clients via a Shared Access Signature.";
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
ms.Position = 0;
using (ms)
{
blob.UploadFromStream(ms);
}
//Set the expiry time and permissions for the blob.
//In this case the start time is specified as a few minutes in the past, to mitigate clock skew.
//The shared access signature will be valid immediately.
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(4);
sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;
//Generate the shared access signature on the blob, setting the constraints directly on the signature.
string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return blob.Uri + sasBlobToken;
}
示例13: DownloadBlob
public static void DownloadBlob(CloudBlobContainer container)
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference("photo1.jpg");
using (var fileStream = System.IO.File.OpenWrite(@"path\myfile"))
{
blockBlob.DownloadToStream(fileStream);
}
}
示例14: UploadFileWithContainerUri
/// <summary>
/// Upload files by using Container Uri
/// </summary>
/// <param name="sasUri"></param>
/// <param name="localFilePath"></param>
/// <param name="filePathInSyncFolder"></param>
public bool UploadFileWithContainerUri(string sasUri, string localFilePath,
string filePathInSyncFolder, string fileHashVaule, DateTime fileTimestamp, string eventType)
{
try
{
CloudBlobContainer container = new CloudBlobContainer(new Uri(sasUri));
if (fileHashVaule == "isDirectory")
{
CloudBlockBlob blob = container.GetBlockBlobReference(filePathInSyncFolder);
LocalFileSysAccess.LocalFileSys uploadfromFile = new LocalFileSysAccess.LocalFileSys();
uploadfromFile.uploadfromFilesystem(blob, localFilePath, eventType);
//blob.UploadFromFile(localFilePath, FileMode.Open);
//directory.Metadata["hashValue"] = fileHashVaule;
}
else
{
CloudBlockBlob blob = container.GetBlockBlobReference(filePathInSyncFolder);
LocalFileSysAccess.LocalFileSys uploadfromFile = new LocalFileSysAccess.LocalFileSys();
uploadfromFile.uploadfromFilesystem(blob, localFilePath, eventType);
//blob.UploadFromFile(localFilePath, FileMode.Open);
blob.Metadata["hashValue"] = fileHashVaule;
blob.Metadata["timestamp"] = fileTimestamp.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss");
blob.Metadata["filePath"] = filePathInSyncFolder;
//blob.Metadata["Deleted"] = "false";
blob.SetMetadata();
blob.CreateSnapshot();
}
}
catch (Exception e)
{
Program.ClientForm.addtoConsole(e.ToString());
Console.WriteLine(e.Message);
//MessageBox.Show("-----------" + e.Message);
return false;
}
return true;
}
示例15: getMetaData
static void getMetaData(CloudBlobContainer container, string filename)
{
CloudBlockBlob blob = container.GetBlockBlobReference(filename);
blob.FetchAttributes();
foreach (var atr in blob.Metadata)
{
Console.WriteLine(atr.Key + " " + atr.Value);
}
}