I am copying some files from Azure Media Services to Azure blob storage and a lot of files get copied successfully but periodically some files get copied over and have a zero byte file size. I'm not sure why this would happen for some files and not others? They are all being copied over via URL from Azure Media Services.
var blob = container.GetBlobClient(fileName);
var operation = blob.StartCopyFromUriAsync(new Uri(url));
var fileSize = await operation.WaitForCompletionAsync(
DelayStrategy.CreateExponentialDelayStrategy(
initialDelay: TimeSpan.FromSeconds(1), maxDelay: TimeSpan.FromMinutes(5)),
CancellationToken.None);
// fileSize == 0 sometimes!
According to this MS-Documentation, the problem with the
StartCopyFromUriAsyncmethod when copying zero-byte files from Azure Media Services to Azure Blob Storage is due to:If the
copy operationis aborted before it completes. When you abort a copy operation, the destination blob will have a zero length.The copy operation is not guaranteed to start immediately or complete within a specified time frame and is performed on a best-effort basis.
You can use the code below to copy operation fails and the destination blob has a zero length. If the copy operation succeeds, it prints a message to the console with the size of the destination blob using .net.
Code:
Output:
Also, You can refer this Azure data movement Library to Copy a file from URL to a blob.