从Azure Blob存储下载Blob列表

时间:2019-08-12 14:21:36

标签: java azure spring-boot azure-storage-blobs

我用正确的连接字符串创建了count ( $data->toggle_multi_tiles ) ;

" use vim settings, rather than vi settings. this setting must be as
early as
" possible, as it has side effects. this is required for vundle.
set nocompatible
filetype off

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" add other plugins here...
Plugin 'jamessan/vim-gnupg'
Bundle 'croaky/vim-colors-github'

" All of your Plugins must be added before the following line
call vundle#end()               " required
filetype plugin indent on       " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
~                    

$ vim ~/.vimrc
Error detected while processing /home/tridip/.vimrc:
line    2:
E492: Not an editor command: early as
line    9:
E117: Unknown function: vundle#begin
line   12:
E492: Not an editor command: Plugin 'gmarik/Vundle.vim'
line   15:
E492: Not an editor command: Plugin 'jamessan/vim-gnupg'
line   16:
E492: Not an editor command: Bundle 'croaky/vim-colors-github'
line   19:
E117: Unknown function: vundle#end
Press ENTER or type command to continue

我使用import psutil import logging logging.basicConfig(level=logging.INFO) process_list = [p.info for p in psutil.process_iter(attrs=['pid', 'name']) if 'firefox' in p.info['name']] for process in process_list: logging.info('process name %s' % process['name']) 查看了blob列表

当前,我正在寻找从特定文件夹下载列表Blob的最有效方法。

3 个答案:

答案 0 :(得分:1)

listBlobs()方法有一个overload,它接受​​prefix作为参数。

public Iterable<ListBlobItem> listBlobs(final String prefix, final boolean useFlatBlobListing) {
        return this.listBlobs(prefix, useFlatBlobListing, EnumSet.noneOf(BlobListingDetails.class), null, null);
    }

您需要将path of the folder作为prefix传递,并将true传递给useFlatBlobListing,这将列出该虚拟文件夹中的所有Blob。

一旦有了该blob列表,就可以使用downloadToFile方法在每个blob上下载blob。

答案 1 :(得分:1)

一段时间后,我发现可以将CloudBlockBlob类型应用于ListBlobItem并下载方法。

@Bean
@SneakyThrows
public CommandLineRunner commandLineRunner(CloudBlobContainer blobContainer) {
    return args -> {
        Sets.newConcurrentHashSet(blobContainer.listBlobs("documents/"))
                .stream()
                .filter(it -> it.getUri().toString().contains("pdf"))
                .forEach(it -> {
                    ((CloudBlockBlob) it).downloadToFile(((CloudBlockBlob) it).getName());
                });

    };
}

谢谢大家。特别是@GauravMantri

答案 2 :(得分:0)

您可以通过两种方式完成

(i) AZcopy -AzCopy /Source:https://myaccount.file.core.windows.net/demo/ /Dest:C:\myfolder /SourceKey:key /S

(ii)通过 Azure Cli -

# Create a directory to store all the blobs
mkdir /downloaded-container && cd /downloaded-container

# Get all the blobs
BLOBS=$(az storage blob list -c $CONTAINER \
    --account-name $ACCOUNT_NAME --sas-token "$SAS_TOKEN" \
    --query [*].name --output tsv)

# Download each one
for BLOB in $BLOBS
do
  echo "********Downloading $BLOB"
  az storage blob download -n $BLOB -f $BLOB -c $CONTAINER --account-name $ACCOUNT_NAME --sas-token "$SAS_TOKEN"
done

如果只希望通过代码进行操作,则这里为 sample repo ,因为没有直接方法可以通过SDK进行操作。

HttpGet httpGet = new HttpGet(urlString);
            signRequest(httpGet, resourcePath, account, hashFunction);
            try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
                System.out.println(response.getStatusLine());