LoginSignup
1
0

More than 5 years have passed since last update.

Azure Storage Client Library for .NET で Blob 追加と同時に Conetnt-Type を設定する

Last updated at Posted at 2016-04-07

この記事ではWindowsAzure.Storage v6.2.0を使っています。

var blockBlobReference = container.GetBlockBlobReference(name);
blockBlobReference.Properties.ContentType = "image/jpg";
blockBlobReference.UploadFromStream(stream);

最初↑の方法を知らなくて↓の記事を書きました。
↑がよりよいライブラリーの使い方だと思います。


x-ms-blob-content-type を使用する。

var blockBlobReference = container.GetBlockBlobReference(name);
var headers = new Dictionary<string, string> { { "x-ms-blob-content-type", "image/jpeg" } };
var operationContext = new OperationContext { UserHeaders = headers };

blockBlobReference.UploadFromStream(stream, operationContext: operationContext);

UploadFromFileなどのメソッドはoperationContextパラメーターを渡すことで追加のリクエストヘッダーを設定できる。
Content-Type はクライアントでは直接指定できない。
'Content-Type' ヘッダーは、適切なプロパティまたはメソッドを使用して変更する必要があります。


OperationContext.UserHeaders プロパティ
Put Blob

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0