/// <summary> /// Retreives information about a blob, but not the actual data /// </summary> public BlobInfo GetBlobInfo(string containerName, string blobPath) { BlobInfo info = null; try { // Retreive the container CloudBlobContainer container = _blobClient.GetContainerReference(containerName); // If the container exists, then grab it if (container.Exists()) { CloudBlockBlob fileBlob = container.GetBlockBlobReference(blobPath); // If the blob exists, then download it to a memory stream if (fileBlob.Exists()) { fileBlob.FetchAttributes(); info = BlobInfo.FromBlob(fileBlob); } } } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.ToString()); throw; } return(info); }
/// <summary> /// Creates a new blob at the specified location. If the blob already exists, the content will be overwritten. /// </summary> public BlobInfo CreateBlob(string containerName, string blobPath, Stream data) { BlobInfo blobInfo; try { // Retreive the container CloudBlobContainer container = _blobClient.GetContainerReference(containerName); // Create the container if it doesn't already exist. container.CreateIfNotExists(); // Get a reference to the blob, so we can either create it or overwrite it CloudBlockBlob fileBlob = container.GetBlockBlobReference(blobPath); // Upload the bytes fileBlob.UploadFromStream(data); blobInfo = BlobInfo.FromBlob(fileBlob); } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.ToString()); throw; } return(blobInfo); }