2021年4月6日星期二

Azure blob file download failed after downloading a few files

I tried to download blob files using BlobClient.downloadToFile(dest), but it failed after downloading a few files. I faced the same issue while trying to download a 3GB single file from Azure Blob storage.

package com.blob.download;  import com.azure.storage.blob.BlobContainerClient;  import com.azure.storage.blob.BlobServiceClient;  import com.azure.storage.blob.BlobServiceClientBuilder;  import com.azure.storage.blob.models.BlobItem;  import com.azure.storage.blob.models.ListBlobsOptions;  import java.io.IOException;  import java.nio.file.Files;  import java.nio.file.Path;  import java.nio.file.Paths;  import java.util.Iterator;  public class BlobDownload {      public static void main(String args[]){          BlobServiceClientBuilder builder = new BlobServiceClientBuilder();          //Specify storage uri          String storageBaseUri = "";          ///Specify connection string          String connectionString = "";          //Specify key          String key = "";          builder.connectionString(connectionString);          BlobServiceClient client = builder.buildClient();          if (!storageBaseUri.startsWith(client.getAccountUrl())) {              throw new IllegalArgumentException(                      "The given credential can not be used for the specified container.");          }          String containerName = storageBaseUri.replace(client.getAccountUrl() + "/", "");          BlobContainerClient blobContainerClient = client.getBlobContainerClient(containerName);          System.out.println("Downloading " + blobContainerClient.getBlobContainerName() + "/" + key);          Iterator<BlobItem> keyspaceBlobs =                  blobContainerClient.listBlobs(new ListBlobsOptions().setPrefix(key + "/"), null).iterator();          while (keyspaceBlobs.hasNext()){              BlobItem blob = keyspaceBlobs.next();              Path destFile = Paths.get("/opt/data/", blob.getName());              try {                  Files.createDirectories(destFile.getParent());              } catch (IOException e) {                  System.out.println(e);              }              blobContainerClient                      .getBlobClient(blob.getName())                      .downloadToFile(destFile.toString());              System.out.println("Download file succeeded : " + destFile.toString());          }      }  }  

Dependencies

nettyTcNativeVersion = '2.0.7.Final'  compile group: 'com.azure', name: 'azure-storage-blob', version: '12.4.0'  compile group: 'com.azure', name: 'azure-identity', version: '1.0.6'  

I have got the following error message

Exception in thread "main" reactor.core.Exceptions$ReactiveException: java.io.IOException: Connection reset by peer      at reactor.core.Exceptions.propagate(Exceptions.java:393)      at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:97)      at reactor.core.publisher.Mono.block(Mono.java:1678)      at com.azure.storage.common.implementation.StorageImplUtils.blockWithOptionalTimeout(StorageImplUtils.java:99)      at com.azure.storage.blob.specialized.BlobClientBase.downloadToFileWithResponse(BlobClientBase.java:563)      at com.azure.storage.blob.specialized.BlobClientBase.downloadToFile(BlobClientBase.java:488)      at com.azure.storage.blob.specialized.BlobClientBase.downloadToFile(BlobClientBase.java:457)      at com.blob.download.BlobDownload.main(BlobDownload.java:57)      Suppressed: java.lang.Exception: #block terminated with an error          at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)          ... 6 more  Caused by: java.io.IOException: Connection reset by peer      at sun.nio.ch.FileDispatcherImpl.read0(Native Method)      at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)      at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)      at sun.nio.ch.IOUtil.read(IOUtil.java:192)      at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)      at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:247)      at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1147)      at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347)      at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)      at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700)      at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635)      at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552)      at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514)      at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)      at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)      at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)      at java.lang.Thread.run(Thread.java:748)  

Can you please guide me if there is any wrong usage in my implementation?

https://stackoverflow.com/questions/66978309/azure-blob-file-download-failed-after-downloading-a-few-files April 07, 2021 at 09:06AM

没有评论:

发表评论