CopyBlob Method

Copies a blob.

Syntax

QString CopyBlob(const QString& qsSrcBlob, const QString& qsDestBlob, const QString& qsDestContainer);

Remarks

This method copies the specified SrcBlob (in the container currently selected by Container) to the specified DestBlob in DestContainer. If this method finishes successfully, it will either return an asynchronous copy Id, or an empty string (if the copy has finished already).

If Snapshot is non-empty, the specified snapshot of SrcBlob will be used as the copy source. In this case, DestBlob may be the same blob as SrcBlob to "promote" the snapshot, copying its contents back to the base blob.

If DestContainer is empty, the current value of Container is used instead. If DestContainer in non-empty, the value will automatically be lowercased when preparing the request.

If DestBlob already exists, and is the same type of blob as SrcBlob, then it will be overwritten if Overwrite is enabled. However, any snapshots associated with the existing blob are retained.

If DestBlob already exists and has an active infinite-duration lease, its lease Id must be specified using LeaseId, or the request will fail. (If it exists and has an active fixed-duration lease, the request will always fail.)

If the SendMetadataOnCopy configuration setting is enabled when this method is called, all items in the Metadata* properties will be sent in the copy request and applied to DestBlob. Otherwise, the server will copy the metadata items from SrcBlob to DestBlob.

If the request succeeds, this method will always populate the CopyId and CopyStatus configuration settings (and clear CopyProgress and CopyStatusDesc).

Asynchronous Copy Notes

As mentioned, this method will return a copy operation Id if the copy operation was started asynchronously. In this case, use the GetBlobInfo method to poll the DestBlob blob's information, which will cause the CopyStatus, CopyStatusDesc, and CopyProgress configuration settings to be refreshed.

A copy operation whose CopyStatus is still pending may also be aborted by passing the copy operation Id returned by this method (or later retrieved from CopyId) to the AbortCopy method.

// Copy a blob to another location within the same container.
string copyResult = azureblob.CopyBlob("important.zip", "secrets.zip", "");

// If the returned value *isn't* empty string, then we'll monitor the status of the
// asynchronous copy operation by polling once every 2 seconds using GetBlobInfo().
if (!string.IsNullOrEmpty(copyResult)) {
  do {
    azureblob.GetBlobInfo("secrets.zip");
    Console.WriteLine("Copy progress: " + azureblob.Config("CopyProgress"));
  } while (azureblob.Config("CopyStatus") == "pending");
}

Error Handling

This method returns a String value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 Qt Edition - Version 20.0 [Build 8265]