How can I upload file to Azure Blob Storage Using Classic ASP?
I am trying to upload files to Azure Blob Storage using Classic ASP (no choice!). However although I can use can list container contents using MSXML2.ServerXMLHTTP I am failing to create blobs. I need to use it to upload PDF files so am using BlockBlob.
I believe I am failing to create the authorisation key correctly. Does anyone have a code sample of creating the authorisation key in Classic ASP VBScript? I have something like below but have no idea how to generate the key in Classic ASP.
' replace with your account's settings
' setup the URL
baseUrl = "https://<myaccount>.blob.core.windows.net"
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
PathUrl = baseUrl & "/test/myblob"
' setup the request and authorization
http.open "PUT", PathUrl , false
'How do I generate this key from the headers and path using HMAC-SHA256 and my prim/sec account key
http.setRequestHeader "Authorization", "SharedKey <myaccount>:?????"
http.setRequestHeader "Date", "2011-6-16 9:22"
http.setRequestHeader "x-ms-date", "2011-06-16 9:22"
http.setRequestHeader "x-ms-version", "2009-09-19"
http.setRequestHeader "Content-Length", "11"
http.setRequestHeader "x-ms-blob-type","BlockBlob"
http.setRequestHeader "Content-Type", "text/plain; charset=UTF-8"
postData = "hello world"
' send the POST data
http.send postData
' optionally write out the response if you need to check if it worked
Response.Write http.responseText
I get the erro开发者_如何学JAVAr AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Thanks
Graeme
You would have to implement the equivalent of the algorithm defined here:
http://msdn.microsoft.com/en-us/library/dd179428.aspx
However, there is an easier way that I recommend if possible. I would have your ASP application make a ASMX (or WCF equivalent call) to a .NET application that returns a shared access signature (SAS) with a short life (e.g. with 10 min expiry). Just pass the name of the PDF you will upload and have it calculate a signature for you with write access. Once you have the signature, you can simply PUT against it without worrying about calculating anything. If the PDF is very large (> 64MB), you will have an issue where you need to worry about breaking into blocks, but for smallish PDFs you can do a very simple PUT operation on the SAS without worrying about it.
The code for this is trivial:
var blobName = "foo.pdf"; //taken from ASP app
var blob = container.GetBlobReference(blobName);
var sas = blob.GetSharedAccessSignature(new SharedAccessPolicy()
{
Permissions = SharedAccessPermissions.Write,
SharedAccessExpiryTime = DateTime.AddMinutes(10)
});
The container in this case is whereever you want users to upload. The 'sas' variable will contain the querystring portion that you need to send. You just need to append it (e.g. blob.Uri.AbsoluteUri + sas).
With this solution, your ASP app is ignorant of Windows Azure blob storage and the details and only your .NET app needs to know the key or how to calculate a SAS.
You can upload files to azure storage using simple C# application. Please refer the link for more details. < http://tuvian.wordpress.com/2011/06/24/how-to-upload-blob-to-azure-using-asp-net-tool-for-upload-files-to-azure-using-asp-netc/ >
精彩评论