是否可以将容器的整个Blob(具有文件)复制到Java中的另一个预订容器Blob [英] Is it possible to copy whole blob of a container (having files)to another subscription container blob in java
问题描述
我想从blob复制数据,例如storageaccount/container/folder1/folder2/folder3.现在,我想将folder3数据复制到另一个订阅容器blob.
I want to copy data from blob e.g storageaccount/container/folder1/folder2/folder3 . Now I want to copy folder3 data to another subscription container blob.
我正在使用java和azure sdk,startcopy使用SAS将源复制到目标.但每次都说不存在blob.
I am using java and azure sdk, startcopy to copy source to destination using SAS. but everytime it says that blob does not exist.
但是,如果我给出的源路径是这样的:storageaccount/container/folder1/folder2/folder3/xyz.txt,则它能够将数据从源复制到目标. 不能将整个folder3数据复制到目标位置,而不是遍历所有文件吗?
But if source path I give like this : storageaccount/container/folder1/folder2/folder3/xyz.txt then it is able to copy data from source to destination. Cant we copy whole folder3 data to destination?instead of looping through all the files?
推荐答案
您提到了startcopy
方法,假设您使用的是v8 sdk.您说使用storageaccount/container/folder1/folder2/folder3
时会说blob不存在,因为您只提供了一个目录,而
You mention startcopy
method, suppose you are using v8 sdk. You say when use storageaccount/container/folder1/folder2/folder3
it will say that blob does not exist, cause you just provide a directory and the startcopy need the CloudBlockBlob
object.
因此正确的方法应该是在目录下列出blob,然后循环blob并复制blob.下面是我的测试代码,为了进行测试,我只是将目录复制到另一个容器中.
So the right way should be list the blobs under the directory, then loop the blobs and copy the blob. The below is my test code, for test I just copy a directory to another container.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectStr);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
try {
CloudBlobContainer container = blobClient.getContainerReference("test");
Iterable<ListBlobItem> blobs=container.listBlobs("testfolder/");
CloudBlobContainer destcontainer=blobClient.getContainerReference("testcontainer");
for(ListBlobItem blob:blobs){
CloudBlockBlob srcblob=new CloudBlockBlob(blob.getUri());
CloudBlockBlob destblob= destcontainer.getBlockBlobReference(srcblob.getName());
destblob.startCopy(srcblob);
}
} catch (StorageException e) {
e.printStackTrace();
}
Update: about the status about copy action, there is a method getCopyState, you could get the state details, hope this is what you want. More details check the method.
CopyState st=destblob.getCopyState();
System.out.println(st.getStatus());
这篇关于是否可以将容器的整个Blob(具有文件)复制到Java中的另一个预订容器Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!