I\'m trying to upload files to an Azure fileshare using the library Azure.Storage.Files.Shares.
If I don\'t chunk the file (by making a single UploadRange call) it w
I was able to reproduce the issue. Basically the problem is with the following line of code:
new HttpRange(0, uploadChunk.Length)
Essentially you're always setting the content at the same range and that's why the file is getting corrupted.
Please try the code below. It should work. What I did here is defined the HTTP range offset and moving it constantly with number of bytes already written to the file.
using (FileStream stream = fileInfo.OpenRead())
{
file.Create(stream.Length);
//file.UploadRange(new HttpRange(0, stream.Length), stream);
int blockSize = 1 * 1024;
long offset = 0;//Define http range offset
BinaryReader reader = new BinaryReader(stream);
while (true)
{
byte[] buffer = reader.ReadBytes(blockSize);
if (buffer.Length == 0)
break;
MemoryStream uploadChunk = new MemoryStream();
uploadChunk.Write(buffer, 0, buffer.Length);
uploadChunk.Position = 0;
HttpRange httpRange = new HttpRange(offset, buffer.Length);
var resp = file.UploadRange(httpRange, uploadChunk);
offset += buffer.Length;//Shift the offset by number of bytes already written
}
reader.Close();
}