Error while uploading image to blob storage. error: The remote server returned an error: NotFound
-
11 September 2011 21:26
Hi All,
I'm facing an error while uploading image to blob storage from Windows phone 7 using a PUT request.
The Error returned: The remote server returned an error: NotFound
My Code "Was working normally till yesterday, no changes made":
byte[] fileContent = new byte[fileToUpload.Length]; int bytesRead = fileToUpload.Read(fileContent, 0, (int)fileToUpload.Length); //Request Headers string requestMethod = "PUT"; string queryString = "timeout:160"; string dateInRfc1123Format = DateTime.UtcNow.ToString("R", System.Globalization.CultureInfo.InvariantCulture); string canonicalizedHeaders = String.Format("x-ms-blob-type:{0}\nx-ms-date:{1}\nx-ms-version:{2}", blobType, dateInRfc1123Format, msVersion); string canonicalizedResource = String.Format("/{0}/{1}/{2}", accountName, containerName, filename.ToLower()); string stringToSign = String.Format(signatureString, requestMethod, fileContent.Length.ToString(), "", canonicalizedHeaders, canonicalizedResource, queryString); string authorizationHeader = ConstructSignature(stringToSign); string stringUrl = "https://" + accountName + ".blob.core.windows.net/" + containerName + "/" + filename.ToLower() + "?timeout=160"; HttpWebRequest blobClient = (HttpWebRequest)WebRequest.Create(stringUrl); blobClient.Method = requestMethod; blobClient.Headers["x-ms-blob-type"] = blobType; blobClient.Headers["x-ms-date"] = dateInRfc1123Format; blobClient.Headers["x-ms-version"] = msVersion; blobClient.Headers["Authorization"] = String.Format("{0} {1}:{2}", authenticationScheme, accountName, authorizationHeader); blobClient.BeginGetRequestStream(new AsyncCallback(blobClientRequestStreamCallback), new StateObject { request = blobClient, contentToUpload = fileContent });
Tried various things but dead end till now.any idea what could be the problem?
Semua Balasan
-
12 September 2011 8:21Moderator
Hi,
The Error returned: The remote server returned an error: NotFound
Base on the error message, I would like to suggest you to make sure whether the Container exists or not, you can use Azure Storage Explorer to check it or you can try to use get Container properties request to retrieve the properties for the specified container, if the NotFound error is encountered, it means the Container does not exist.
For how to use get Container properties request:
http://msdn.microsoft.com/en-us/library/dd179370.aspx
If the Container dose not exist ,you can follow the article below to create a Container:
http://msdn.microsoft.com/en-us/library/dd179468.aspx
In addition ,it is not recommend to expose the AccountKey(signatureString) on the client side:
1. If you use your own account ,since the account key must be embedded in the project that runs on the client side, it is not safe because users may get the account key via this project.
2. If you let users enter their own account, it is not convenient to type such a long string on the client side(on a mobile phone).
As a result ,I would recommend that you can create a shared access signature which provides access rights to containers and blobs at a more granular level.
Please refer the link below for the detailed information about creating a Shared Access Signature.
http://msdn.microsoft.com/en-us/library/ee395415.aspx
Best Regards,
Ming Xu.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework -
12 September 2011 10:13
Hi Ming,
Thanks a lot for your detailed reply.
The thing is that the container exist and Azure explorer works perfectly with it and this same code was working a couple of days ago. So, any other reason can cause the same behaviour?
Do you know any better method to do the same functionality, may be the PUT request is not that reliable with blobs?
Thanks a lot.
Best Regards,
Amr
-
12 September 2011 12:35
Looks like the authentication is failing. Are you going through a proxy? Did you check your key and account name? If you can get a trace for your request that should help figure what is wrong.
Thanks,
jai
-
12 September 2011 13:36
Hi Jai,
How can I get a trace of what's happening? the call is Async. call and I need to see logs or something from Azure's side. any ideas on how to do this?
Thanks,
Amr
-
12 September 2011 13:58
Sorry, I meant a network trace for the packet. A fiddler trace will be helpful if you can run this from a desktop.
I have not used this myself, but the blog here suggests how you can get a network trace on your phone. You can try using http while debugging this if that does not capture https.
Thanks,
jai
-
18 September 2011 9:44
Dear All,
nothing is working, I can see the request on fiddler now and here's the request:
PUT /container/846930360_4110.png?timeout=160 HTTP/1.1 Accept: */* Referer: file:///Applications/Install/816DE062-C1FF-49B3-A43D-572163ABA053/Install/ Content-Length: 55908 Accept-Encoding: identity x-ms-blob-type: BlockBlob x-ms-date: Sun, 18 Sep 2011 09:20:39 GMT x-ms-version: 2009-09-19 Authorization: SharedKey storageaccount:fdasdfadfadfadfasdfsdfdsdf+npXF9js= User-Agent: NativeHost Host: storageaccount.blob.core.windows.net Connection: Keep-Alive Cache-Control: no-cache Pragma: no-cache
Response:
HTTP/1.1 201 Created Via: 1.1 FRZNTMG-01 Connection: Keep-Alive Proxy-Connection: Keep-Alive Transfer-Encoding: chunked Date: Sun, 18 Sep 2011 09:20:48 GMT ETag: 0x8CE43FB6330B4E2 Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 Content-MD5: g1TA4assauiIDPgjjNgJ/g== Last-Modified: Sun, 18 Sep 2011 09:20:48 GMT x-ms-request-id: 9ccasa1-18c3-4b3c-b20a-a97f7008765e x-ms-version: 2009-09-19
But now and without any changes in code, it doesn't throw any exceptions and the response code is "Created" but nothing is saved in the container and nothing is returned in the application.
So, it says it's created while it's not!!
Any idea? or a better way to do this?
-
19 September 2011 8:19Moderator
Hi,
nothing is saved in the container and nothing is returned in the application.
Base on the network trace, the request seems all right by using PUT. Could you please provide more information about how do you know 'nothing is saved in the container'? Did you fail to get the blob by using GET in your application? I would like to suggest you to use a tool(Azure Storage Explorer) to check whether the image is uploaded to blob successfully or not:
http://azurestorageexplorer.codeplex.com/
If you can get the image by using the tool, from my experience the container may be set as private and if you try to access it without providing key or SAS, the error will be encountered.
If you can not get the image in blob, may be Jai can deal with the issue via the request id.
Best Regards,
Ming Xu.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework -
19 September 2011 13:41
Hi,
Have you checked your container is public or private ..
I am not sure but may be that could be an issue.
cpsingh -
19 September 2011 14:58
can you email me your account name to jharidas at microsoft? We can have a look and get back.
Thanks,
Jai
-
20 September 2011 9:16
Good news: The upload is working now with the same code. however, I still don't know what caused the issue!!
one note, I check images through the management portal and the images was appearing as soon as it's uploaded but now it's uploaded and appear on WP7 application but it show up on the management portal after some time and some of it didn't appear at all. any ideas about this behavour or what should i expect? "The container is public"
Thanks a million
Amr
-
20 September 2011 15:31
I am not sure what you are referring to when you say cannot see it in portal. The fact that you got success from the blob service, the image will be there and will be accessible. Like I mentioned above - trace will help or turning on analytics (logging) for your account will also help you figure what happened to the request.
Thanks,
Jai
-
30 September 2011 4:05
Hi Jai,
I'm getting the same error: "The remote server returned an error: NotFound" in my WP7 app that uses the Windows Azure Toolkit for WP7.
I did not used to get this error couple of months ago, but now this error happen everytime when I'm uploading ~40 files of 1k each. I suspect something change in Windows Azure. Important note: the uploading is always working when the phone is connected to the computer.
Any clue?
Thanks
ArchieCoder
-
02 Oktober 2011 3:46
can you email me your account name etc. using the email I provided above? I would need the following:
1> account name
2> sample request or approximate time of requests and blob names used.
The other option is to go through our support.
Thanks,
Jai
- Diedit oleh Jai HaridasMicrosoft Employee 02 Oktober 2011 3:46
-
08 Maret 2012 11:43
hi casper.
Can you give me project for this.?
KArthik