public void CopyBlob(string containerName1, string blobName1, string containerName2, string blobName2) { CloudBlobContainer container1 = cloudBlobClient.GetContainerReference(containerName1); CloudBlobContainer container2 = cloudBlobClient.GetContainerReference(containerName2); CloudBlob blob1 = container1.GetBlobReference(blobName1); CloudBlob blob2 = container1.GetBlobReference(blobName2); blob2.CopyFromBlob(blob1); }
public static CloudBlobContainer Duplicate(this CloudBlobContainer container, string newContainerName) { CloudBlobContainer newContainer = CreateContainer(Maps.AzureStorageAccountKey, Maps.AzureStorageAccountName, newContainerName); foreach (CloudBlob blob in container.ListBlobs()) { CloudBlob newBlob = newContainer.GetBlobReference(blob.Name); newBlob.CopyFromBlob(blob); } return(newContainer); }
protected void Run_Click(object sender, EventArgs e) { FreezeUI(); ClearIndicators(); Guid jobID = Guid.NewGuid(); Status.Text = string.Format("Running job {0}.", jobID); DownloadLog.NavigateUrl = string.Format("Log.aspx?JobID={0}", jobID); DownloadLog.Enabled = true; Session["jobID"] = jobID; Session["lastLogRefreshTime"] = DateTime.MinValue; Session["allLogs"] = new List <PerformanceLog>(); Uri pointsBlobUri = null; if (PointsFile.HasFile) { CloudBlob pointsBlob = AzureHelper.CreateBlob(jobID.ToString(), AzureHelper.PointsBlob); using (BlobStream stream = pointsBlob.OpenWrite()) { PointsFile.FileContent.CopyTo(stream); } pointsBlobUri = pointsBlob.Uri; } else if (!string.IsNullOrEmpty(PointsBlob.Text)) { CloudBlob pointsBlob = AzureHelper.CreateBlob(jobID.ToString(), AzureHelper.PointsBlob); pointsBlob.CopyFromBlob(AzureHelper.GetBlob(new Uri(PointsBlob.Text))); pointsBlobUri = pointsBlob.Uri; } int nInt = 0, kInt = 0, maxIterationCountInt = 0; int.TryParse(N.Text, out nInt); int.TryParse(K.Text, out kInt); int.TryParse(MaxIterationCount.Text, out maxIterationCountInt); KMeansJobData jobData = new KMeansJobData(jobID, nInt, pointsBlobUri, kInt, maxIterationCountInt, DateTime.Now) { ProgressEmail = ProgressEmail.Text }; AzureHelper.EnqueueMessage(AzureHelper.ServerRequestQueue, jobData); WaitForResults(); }
// Copy a blob. // Return true on success, false if unable to create, throw exception on error. public bool CopyBlob(string sourceContainerName, string sourceBlobName, string destContainerName, string destBlobName) { try { CloudBlobContainer sourceContainer = BlobClient.GetContainerReference(sourceContainerName); CloudBlob sourceBlob = sourceContainer.GetBlobReference(sourceBlobName); CloudBlobContainer destContainer = BlobClient.GetContainerReference(destContainerName); CloudBlob destBlob = destContainer.GetBlobReference(destBlobName); destBlob.CopyFromBlob(sourceBlob); return(true); } catch (StorageClientException ex) { if ((int)ex.StatusCode == 404) { return(false); } throw; } }
/// <summary> /// Renames the specified object by copying the original to a new path and deleting the original. /// </summary> /// <param name="originalPath">The original path.</param> /// <param name="newPath">The new path.</param> /// <returns></returns> public StorageOperationResult Rename(string originalPath, string newPath) { var u = new Uri(newPath, UriKind.RelativeOrAbsolute); CloudBlobContainer c = GetContainerReference(ContainerName); newPath = UriPathToString(u); if (newPath.StartsWith("/")) { newPath = newPath.Remove(0, 1); } originalPath = UriPathToString(new Uri(originalPath, UriKind.RelativeOrAbsolute)); if (originalPath.StartsWith("/")) { originalPath = originalPath.Remove(0, 1); } CloudBlob newBlob = c.GetBlobReference(newPath); CloudBlob originalBlob = c.GetBlobReference(originalPath); // Check if the original path exists on the provider. if (!CheckBlobExists(originalPath)) { throw new FileNotFoundException("The path supplied does not exist on the storage provider.", originalPath); } newBlob.CopyFromBlob(originalBlob); try { newBlob.FetchAttributes(); originalBlob.Delete(); return(StorageOperationResult.Completed); } catch (StorageClientException e) { throw; } }
public void CopyFrom(IStreamingItem sourceItem, StreamingCondition condition, StreamingCondition copySourceCondition, StreamingWriteOptions writeOptions) { var item = sourceItem as BlobStreamingItem; if (item != null) { try { _blob.CopyFromBlob(item._blob, Map(condition, copySourceCondition)); } catch (StorageClientException e) { switch (e.ErrorCode) { case StorageErrorCode.BlobNotFound: throw StreamingErrors.ItemNotFound(this, e); default: throw; } } } else { // based on the default write block size of BLOB const int bufferSize = 0x400000; Write( targetStream => sourceItem.ReadInto( (props, stream) => stream.CopyTo(targetStream, bufferSize), copySourceCondition), condition, writeOptions); } }
public void SaveProperties() { CloudBlob blob = Blob.CloudBlob; foreach (Property prop in Properties) { switch (prop.PropertyName) { case "(Name)": if (prop.PropertyValue != BlobDescriptor.BlobName(blob)) { CloudBlobContainer container = blob.Container; if (container != null) { CloudBlob newBlob = container.GetBlobReference(prop.PropertyValue); newBlob.UploadText(String.Empty); newBlob.CopyFromBlob(blob); blob.Delete(); blob = newBlob; } } break; case "Blob Type": // Can't be set - blob.Properties.BlobType = prop.PropertyValue; break; case "CacheControl": blob.Properties.CacheControl = prop.PropertyValue; break; case "ContentEncoding": blob.Properties.ContentEncoding = prop.PropertyValue; break; case "ContentLanguage": blob.Properties.ContentLanguage = prop.PropertyValue; break; case "ContentMD5": blob.Properties.ContentMD5 = prop.PropertyValue; break; case "ContentType": blob.Properties.ContentType = prop.PropertyValue; break; case "ETag": //Can't be set - blob.Properties.ETag = prop.PropertyValue; break; case "LastModifiedUtc": //Can't be set break; case "Length": break; } } blob.SetProperties(); }
public void Copy(CloudBlob source, CloudBlob target) { target.CopyFromBlob(source); }