GetBlobReferenceFromServer and UploadFromStream #138

Closed
xied75 opened this Issue Nov 30, 2012 · 3 comments

Projects

None yet

3 participants

@xied75
xied75 commented Nov 30, 2012
ICloudBlob blob = ctn.GetBlobReferenceFromServer("myabc.txt");
using (FileStream fs = new FileStream("c:\\temp\\test.txt", FileMode.Open))
{
    blob.UploadFromStream(fs); ///not using largefileopts here
}

Will throw "Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()"

ICloudBlob blob = ctn.GetBlockBlobReference("myabc.txt");
using (FileStream fs = new FileStream("c:\\temp\\test.txt", FileMode.Open))
{
    blob.UploadFromStream(fs); ///not using largefileopts here
}

Works just fine. If I make a 1024B text file, this also works for a pageblob.
It's reasonable for the first one to fail because the library code has no idea what kind of Blob you want to create, while the 2nd code can infer the type.

But MSDN doesn't mention this method is supposed to target an existing blob ONLY.
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.getblobreferencefromserver.aspx

And the error msg, probably it's better to complain that I don't know what type of the ICloudBlob is, other than saying the Blob is not found?

Best,

dong

Edit:
The ICloudBlob even has a method of Exists(), pointless if the ICloudBlob is created by calling GetBlobReferenceFromServer().

@joeg
joeg commented Apr 9, 2013

GetBlobReferenceFromServer() is intended for use when the client does not know what type of blob already exists. It will do the same HEAD request that the exists method does, but this method will return the appropriate blob object instance to allow the client to perform actions on it. This method should only be used when you know the blob is on the server, or are prepared to handle the not found exception in the case when it doesn't.

@joeg joeg closed this Apr 9, 2013
@xied75
xied75 commented Apr 9, 2013

Hi, Joeg,

In both code blocks I was trying to "Create" new blob, I wasn't trying to access existing blobs. And I was trying to point out that given the same purpose, one method does work the other doesn't, but on MSDN there is no mentioning of it at all.

Like what you said "This method should only be used when ......", as users of the SDK we can always figure out by trail and error, BUT what you said is not on MSDN, this is the point.

Best regards,

Dong

@joeg
joeg commented Apr 9, 2013

You are correct, and I have notified our Doc team to address this as soon as possible. I apologize for the confusion, we are actively working to improve our documentation.

@jeffreyjirwin jeffreyjirwin was unassigned by xied75 Apr 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment