1

こんにちは、Azure BLOB サービス API http://msdn.microsoft.com/en-us/library/dd135733.aspx

c# を使用して呼び出すことができます。Word文書などのファイルを保存場所にアップロードしたいのですが、httpメソッドは「put」で、残りのURLは

" http://myaccount.blob.core.windows.net/mycontainer/myblob "

このコードは動作しますか?

string username = "user";
string password = "password";
string data = "path to word document;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "PUT";
request.Credentials = new NetworkCredential(username, password);
request.ContentLength = data.Length;
request.ContentType = "text/plain";

using (StreamWriter writer = new StreamWriter(request.GetRequestStream( ))) {
  writer.WriteLine(data);
}

WebResponse response = request.GetResponse( );

using (StreamReader reader = new StreamReader(response.GetResponseStream( ))) {
  while (reader.Peek( ) != -1) {
  Console.WriteLine(reader.ReadLine( ));
4

1 に答える 1

1

いいえ、これは機能しません。Windows Azureストレージへの認証には、リクエストのヘッダーへの署名が含まれます。(http://msdn.microsoft.com/en-us/library/dd179428.aspxを参照してください。)

SDKに付属している.NETStorageClientライブラリは再配布可能であるため、そのライブラリへの参照を追加して(メモリから)実行できることに注意してください。

 CloudStorageAccount.Parse("<connection string>")
    .CreateCloudBlobClient()
    .GetBlobReference("mycontainer/myblob")
    .UploadByteArray(data);
于 2010-07-28T17:18:03.397 に答える