c# - Azure copy blob container contents to another container -
i'm having issues getting blob container copy on container. when copy complete in target location file no extension. there should bunch of images source container. i'm trying achieve creating backup of entire containers blobs. case container 0100, actual blobs in 0100/photos/student/ - if there better way please let me know!
string sblobconnstring = configurationmanager.appsettings["smartblobstorageconn"]; cloudstorageaccount storageaccount = cloudstorageaccount.parse(sblobconnstring); //create blob client cloudblobclient blobclient = storageaccount.createcloudblobclient(); cloudblobcontainer container = blobclient.getcontainerreference(srccontainer); if (container.exists()) { cloudblobdirectory source = container.getdirectoryreference(blobname); var target = container.getblockblobreference(destblobname); var blobs = source.listblobs(); foreach (var blob in blobs) { target.startcopyfromblob(blob.uri); copystates.add(target.copystate); } }
for interested here solution on how copy azure blob virtual directory.
public static void copydirectory(string srccontainer, string srcdirectory, string destcontainer, string destdirectory) { cloudblobdirectory sourceblobdir = getcloudblobdirectory(srccontainer, srcdirectory); cloudblobdirectory destblobdir = getcloudblobdirectory(destcontainer, destdirectory); copydirectoryoptions options = new copydirectoryoptions() { recursive = true, }; transfercontext context = new transfercontext(); // create cancellationtokensource used cancel transfer cancellationtokensource cancellationsource = new cancellationtokensource(); try { transfermanager.copydirectoryasync(sourceblobdir, destblobdir, false /* isservicecopy */, options, context, cancellationsource.token); } catch (system.exception ex) { throw ex; } }
Comments
Post a Comment