首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以复制天蓝色斑点文件夹而不遍历每个斑点文件吗?

我可以复制天蓝色斑点文件夹而不遍历每个斑点文件吗?
EN

Stack Overflow用户
提问于 2019-11-04 18:18:50
回答 1查看 675关注 0票数 0

目前我使用golang来实现将文件从一个存储帐户复制到另一个存储帐户。

例如:

代码语言:javascript
复制
https://storage1.blob.core.windows.net/container/A/B/file1.mp4
https://storage1.blob.core.windows.net/container/A/B/file2.mp4
https://storage1.blob.core.windows.net/container/A/B/file3.mp4


Copy from

https://storage1.blob.core.windows.net/container/A/B/
to 
https://storage2.blob.core.windows.net/container/A/B/

是否可以复制整个文件夹而不遍历A/B文件夹中的所有文件?

下面是我的示例代码

代码语言:javascript
复制
func (css StorageOperator) NestedListBlobs(ctx context.Context, srcFolderPath string) ([]azblob.BlobURL, error) {

    containerName, folderPath := css.getContainerNameAndPath(srcFolderPath)
    containerRawUrl := "https://" + css.StorageName + "." + lib.AzureBlobUrl + "/" + containerName
    containerUrl, _ := url.Parse(containerRawUrl)
    po := azblob.NewPipeline(css.sharedKeyCredential, css.createPipelineOptions())
    container := azblob.NewContainerURL(*containerUrl, po)

    var blobUrls []azblob.BlobURL

    // List the blob(s) in our container; since a container may hold millions of blobs, this is done 1 segment at a time.
    for marker := (azblob.Marker{}); marker.NotDone(); {
        // The parens around Marker{} are required to avoid compiler error.
        // Get a result segment starting with the blob indicated by the current Marker.
        listBlob, err := container.ListBlobsFlatSegment(ctx, marker, azblob.ListBlobsSegmentOptions{
            Prefix: folderPath,
        })
        if err != nil {
            return nil, err
        }
        // IMPORTANT: ListBlobs returns the start of the next segment; you MUST use this to get
        // the next segment (after processing the current result segment).
        marker = listBlob.NextMarker

        // Process the blobs returned in this result segment (if the segment is empty, the loop body won't execute)
        for _, blobInfo := range listBlob.Segment.BlobItems {
            css.logger.Debugf("Blob name: " + containerRawUrl + "/" + blobInfo.Name)

            blobUrl, _ := url.Parse(containerRawUrl + "/" + blobInfo.Name)
            blobUrls = append(blobUrls, azblob.NewBlobURL(*blobUrl, po))
        }
    }

    return blobUrls, nil
}

func (css StorageOperator) parallelCopyFileToDst(ctx context.Context, po pipeline.Pipeline, dstRawUrl string, srcBlobs []azblob.BlobURL) error {


for _, srcBlob := range srcBlobs {


dstUrl, _ := url.Parse(dstRawUrl + css.extractBlobPath(srcBlob))

dstBlobURL := azblob.NewBlobURL(*dstUrl, po)
srcSASUrl, err := css.createSASURL(css.lukeSharedKeyCredential, srcBlob.String())
if err != nil {
    css.logger.Errorf("createSASURL fail:%v", err)
    return
}
startCopy, err := dstBlobURL.StartCopyFromURL(ctx,
                *srcSASUrl,
                azblob.Metadata{},
                azblob.ModifiedAccessConditions{},
                azblob.BlobAccessConditions{})

if err != nil {
    css.logger.Errorf("startCopy fail:%v", err)
    return
}

if err = css.checkCopyStatus(ctx, dstBlobURL, startCopy); err != nil {
                css.logger.Errorf("checkCopyStatus fail:%v", err)
                return
}


}//for
    return nil
}
EN

回答 1

Stack Overflow用户

发布于 2019-11-05 01:48:54

azure blobs中的文件夹结构不存在,而是使用路径名,所以如果你想在“虚拟文件夹”中复制blobs,你所需要做的就是使用路径,下面是一个列出blobs的python示例:

代码语言:javascript
复制
  ['Virtual-Folder/Boards.png', 'storage2.gif']

因此,为了传输Boards.png blob,您必须在它之前附加文件夹名称,而不是在文件夹内查找。我用python写了一些关于这个例子/问题的教程:https://github.com/adamsmith0016/Azure-storage

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58691342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档