2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ファイルアップロードでタイムアウトが発生する問題

Last updated at Posted at 2018-10-17

■原因

HTTPHttpWebRequestクラスを使ってHTTP接続を作成する際に、
AllowWriteStreamBufferingプロパティに何も指定せず、初期値(true)のままとしていた。

以下URLの「実装時の注意」を見ると、「trueの場合、大規模なデータセットをアップロードするときにパフォーマンスの問題が発生する可能性がある」と記述がある。
https://msdn.microsoft.com/ja-jp/library/system.net.httpwebrequest.allowwritestreambuffering(v=vs.110).aspx

■対応策

以下の1行を追加する。
req.AllowWriteStreamBuffering = false;

//HTTPリクエストを作成する
HttpWebRequest req = PathUtil.getHttpWebRequest(uploadURL, true, new NetworkCredential("ユーザーID", "パスワード"));
req.Method = "POST";
req.ContentType = "multipart/form-data; boundary=" + boundary;
req.ContentLength = fs.Length + requestStart.Length + requestEnd.Length;
req.AllowWriteStreamBuffering = false; //デフォルト値はtrueだが、1GB近いサイズのファイルをアップロードした時の処理遅延対策としてfalseに変更する。

■結果

下表の通り、AllowWriteStreamBufferingプロパティをfalseにすることで、
1GB近いサイズのファイルをアップロードしてもタイムアウトせずアップロードすることが出来た。
result.png

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?