I like to stream large data files over REST directly to a Azure Blob Storage.
Now i face the problem that when I send a filter with 250MB over REST to the Azure Blob Storage, but with 260MB it stuck for ever.
I made an example Project where you can verify this behavior. https://github.com/git9999999/azure-blob-large-file-upload-problem
Question is my Reactive Code correct?
@GetMapping(path = "/trigger-download-to-blob/{fileSizeInMb}")
public void triggerDownloadToBlob(@PathVariable int fileSizeInMb) {
log.info("triggerDownload");
var flux = this.webClient
.get()
.uri("/serve-file/" + fileSizeInMb)
.accept(MediaType.APPLICATION_OCTET_STREAM)
.exchangeToFlux(clientResponse -> clientResponse.body(BodyExtractors.toDataBuffers()));
var destination = "TestDownloadToAzureBlobStorage" + System.currentTimeMillis() + ".pdf";
var blobClientTarget = this.containerClient.getBlobClient(destination);
try (var outputStream = blobClientTarget.getBlockBlobClient().getBlobOutputStream(this.parallelTransferOptions, null, null, null, null)) {
DataBufferUtils.write(flux, outputStream)
.map(DataBufferUtils::release)
.blockLast(Duration.ofHours(22));
outputStream.flush();
} catch (IOException e) {
throw new IllegalStateException(e);
}
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!! end download of {}", destination);
}
2
Answers
The Problem was that I used the
BlobContainerClient
and not theBlobContainerAsyncClient
. TheBlobContainerAsyncClient
has special API's to handle the Flux-"Stuff"Hear is the code that I use now:
And Here is the Example repo with solution https://github.com/git9999999/azure-blob-large-file-upload-problem
Here the Ticket that solve the Problem: https://github.com/Azure/azure-sdk-for-java/issues/35477
The
uploadFile
method now accepts aFlux<DataBuffer>
directly as a request part instead of usingMultipartFile
The file data is streamed using reactive programming with
DataBufferUtils.write
, Check the below code:Output :
Updated code:
Flux<DataBuffer>
the uploadFileToBlobStorage method uses theWebClient
to perform a PUT request with the file’s data as the request body.