PageBlob WritePages gives "The page range specified is invalid." exception on last chunk
-
quarta-feira, 22 de setembro de 2010 17:09
I can call CloudBlob.UploadFile fine. Now I need to deal with larger files so am experimenting with PageBlob. I've called Create and made my file size a multiple of 512. I'm uploading chunks that are multiples of 512. All seems OK until the final chunk when I get the above exception. There are people out there uploading whole VHDs and I can't upload a crummy little jpg. AAGH.
Other posts: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/814cdaf6-e168-401d-942c-053d7b3666a6/
Development Storage version 1.0.0.0, Azure SDK V 1.0
private void Button_Click_5(object sender, RoutedEventArgs e)
{
var client = new Microsoft.WindowsAzure.StorageClient.CloudBlobClient(
Microsoft.WindowsAzure.
CloudStorageAccount.DevelopmentStorageAccount.BlobEndpoint,
Microsoft.WindowsAzure.
CloudStorageAccount.DevelopmentStorageAccount.Credentials
);
var dlg = new System.Windows.Forms.OpenFileDialog() { Filter = "Images|*.jpg|All files|*.*", Title = "Select file to upload" };
dlg.ShowDialog();
var fn = dlg.FileName;
if(fn != null && System.IO.File.Exists(fn))
{
try
{
int blockSize = 512 * 8;
long offset = 0;
var container = client.GetContainerReference("sandpit");
container.CreateIfNotExist();
var pb = container.GetPageBlobReference(System.IO.Path.GetFileName(fn));
var fileSize = new System.IO.FileInfo(fn).Length;
fileSize += (512 - (fileSize % 512));
pb.Create(fileSize);
using (var st = System.IO.File.OpenRead(fn))
{
while (offset < fileSize - 1)
{
var buffer = new byte[blockSize];
var bytesRead = st.Read(buffer, 0, blockSize);
using (var ms = new System.IO.MemoryStream(buffer))
{
pb.WritePages(ms, offset);
}
offset += blockSize;
}
}
}
catch (Microsoft.WindowsAzure.StorageClient.StorageClientException ____)
{
}
catch (Exception ex)
{
}
}
- Movido Brian AurichMicrosoft Employee, Moderator terça-feira, 28 de setembro de 2010 19:17 migration (From:Windows Azure)
Todas as Respostas
-
quarta-feira, 22 de setembro de 2010 18:39
Try printing out the file size and the offset you're writing to at each iteration... presumably it's some little off-by-one error.- Marcado como Resposta ajd quarta-feira, 22 de setembro de 2010 21:52
-
quarta-feira, 22 de setembro de 2010 21:56
Thank you! my last page was too big, I was concentrating too hard on the 512 bit.
FileSize += (BlockSize-(FileSize % BlockSize));

