|
2 | 2 |
|
3 | 3 | import static org.apache.commons.lang3.ObjectUtils.isEmpty;
|
4 | 4 |
|
| 5 | +import com.azure.storage.blob.BlobContainerAsyncClient; |
5 | 6 | import com.azure.storage.blob.BlobContainerClient;
|
| 7 | +import com.azure.storage.blob.BlobServiceAsyncClient; |
6 | 8 | import com.azure.storage.blob.BlobServiceClient;
|
7 | 9 | import com.azure.storage.blob.BlobServiceClientBuilder;
|
8 | 10 | import com.azure.storage.blob.models.ParallelTransferOptions;
|
|
11 | 13 | import java.io.FileOutputStream;
|
12 | 14 | import java.io.IOException;
|
13 | 15 | import java.io.OutputStream;
|
| 16 | +import java.nio.ByteBuffer; |
14 | 17 | import java.nio.file.Files;
|
15 | 18 | import java.nio.file.Path;
|
16 | 19 | import java.security.SecureRandom;
|
@@ -48,11 +51,14 @@ public class AzureBlobBugDownloaderController {
|
48 | 51 | private final WebClient webClient;
|
49 | 52 |
|
50 | 53 | private final ParallelTransferOptions parallelTransferOptions;
|
| 54 | + private final BlobContainerAsyncClient blobContainerAsyncClient; |
51 | 55 |
|
52 | 56 |
|
53 | 57 | public AzureBlobBugDownloaderController(BlobServiceClientBuilder blobServiceClientBuilder) {
|
54 | 58 | this.blobServiceClient = blobServiceClientBuilder.buildClient();
|
55 | 59 | this.containerClient = this.blobServiceClient.getBlobContainerClient(BLOB_CONTAINER_NAME);
|
| 60 | + BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder.buildAsyncClient(); |
| 61 | + this.blobContainerAsyncClient = blobServiceAsyncClient.getBlobContainerAsyncClient(BLOB_CONTAINER_NAME); |
56 | 62 | log.debug("technicalAppIp '{}' technicalAppPort '{}'", "8545", "8545");
|
57 | 63 | this.webClient = msCommonWebClientBuilder().baseUrl(createUrl("client", "localhost", "8545")).build();
|
58 | 64 |
|
@@ -156,6 +162,31 @@ public void triggerDownloadToBlob(@PathVariable int fileSizeInMb) {
|
156 | 162 | }
|
157 | 163 |
|
158 | 164 |
|
| 165 | + @GetMapping(path = "/trigger-download-to-blob-working-ok/{fileSizeInMb}") |
| 166 | + public void triggerDownloadToBlobWorkingOk(@PathVariable int fileSizeInMb) { |
| 167 | + log.info("triggerDownloadToBlob"); |
| 168 | + |
| 169 | + var flux = this.webClient |
| 170 | + .get() |
| 171 | + .uri("/serve-file/" + fileSizeInMb) |
| 172 | + .accept(MediaType.APPLICATION_OCTET_STREAM) |
| 173 | + .exchangeToFlux(clientResponse -> clientResponse.body(BodyExtractors.toDataBuffers())); |
| 174 | + |
| 175 | + var destination = "TestDownloadToAzureBlobStorage" + System.currentTimeMillis() + ".pdf"; |
| 176 | + |
| 177 | + var blobClientTarget = this.blobContainerAsyncClient.getBlobAsyncClient(destination); |
| 178 | + |
| 179 | + blobClientTarget.upload(flux.map(dataBuffer -> { |
| 180 | + ByteBuffer buffer = ByteBuffer.allocate(dataBuffer.readableByteCount()); |
| 181 | + dataBuffer.toByteBuffer(buffer); |
| 182 | + DataBufferUtils.release(dataBuffer); |
| 183 | + return buffer; |
| 184 | + }), this.parallelTransferOptions).block(); |
| 185 | + |
| 186 | + log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!! end download of {}", destination); |
| 187 | + } |
| 188 | + |
| 189 | + |
159 | 190 | /**
|
160 | 191 | * https://stackoverflow.com/questions/76575117/can-not-transfer-more-than-250mb-with-databufferutils-write-to-azure-blob-storag/76580753#76580753
|
161 | 192 | */
|
|
0 commit comments