繁体   English   中英

如何使用 java sdk 在 Azure Blob 存储中上传单个视频文件的多个块?

[英]How to upload multiple chunks of a single video file in Azure Blob Storage using java sdk?

我想将一个大文件从 s3(4.5GB 大小)传输到 Azure blob Storage 作为单个文件。 由于它是一个巨大的文件,我们试图将该 s3 文件分成多个块大小为 5MB 的块。 Each chunk is uploaded to azure blob storage and at the end i wanted reassemble all the chunks into single blob file in azure (or) every chunk which i'm uploading to azure blob storage should append it to the existing one.

如果我们对此有任何解决方案,请尽快帮助我?

Azure 存储支持通过Block Blob进行分块上传。 您可以“暂存”数据块,然后在完成所有数据块的上传后,您可以将暂存的数据块“提交”到单个 blob。

新的azure-storage-blob Java SDK 提供了BlockBlobClient (和BlockBlobAsyncClient ),它具有用于暂存和提交块的 API。

使用SpecializedBlobClientBuilder 创建 BlockBlobClient 的实例

这是一个示例:

BlockBlobClient blockBlobClient = new SpecializedBlobClientBuilder()
        .connectionString("<your-connection-string>")
        .containerName("<your-container-name>")
        .blobName("<your-blob-name>")
        .buildBlockBlobClient();

String chunkId1 = Base64.getEncoder().encodeToString("1".getBytes());
String chunkId2 = Base64.getEncoder().encodeToString("2".getBytes());
String chunkId3 = Base64.getEncoder().encodeToString("3".getBytes());

byte[] chunk1Bytes = " chunk 1.".getBytes();
byte[] chunk2Bytes = " chunk 2.".getBytes();
byte[] chunk3Bytes = " chunk 3.".getBytes();

ByteArrayInputStream chunk1 = new ByteArrayInputStream(chunk1Bytes);
ByteArrayInputStream chunk2 = new ByteArrayInputStream(chunk2Bytes);
ByteArrayInputStream chunk3 = new ByteArrayInputStream(chunk3Bytes);

// Stage 3 blocks
blockBlobClient.stageBlock(chunkId1, chunk1, chunk1Bytes.length);
blockBlobClient.stageBlock(chunkId2, chunk2, chunk2Bytes.length);
blockBlobClient.stageBlock(chunkId3, chunk3, chunk3Bytes.length);

// Commit all 3 blocks - order of chunkIds matter
BlockBlobItem blockBlobItem = blockBlobClient.commitBlockList(Arrays.asList(chunkId1, chunkId2, chunkId3));


ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
blockBlobClient.download(outputStream);

System.out.println(new String(outputStream.toByteArray())); // prints chunk 1. chunk 2. chunk3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM