以下は私のために働いています:
[HttpPost]
public ActionResult Upload(int? chunk, string name)
{
var fileUpload = Request.Files[0];
var uploadPath = Server.MapPath("~/App_Data");
chunk = chunk ?? 0;
using (var fs = new FileStream(Path.Combine(uploadPath, name), chunk == 0 ? FileMode.Create : FileMode.Append))
{
var buffer = new byte[fileUpload.InputStream.Length];
fileUpload.InputStream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
}
return Json(new { message = "chunk uploaded", name = name });
}
そしてクライアント上で:
$('#uploader').pluploadQueue({
runtimes: 'html5,flash',
url: '@Url.Action("Upload")',
max_file_size: '5mb',
chunk_size: '1mb',
unique_names: true,
multiple_queues: false,
preinit: function (uploader) {
uploader.bind('FileUploaded', function (up, file, data) {
// here file will contain interesting properties like
// id, loaded, name, percent, size, status, target_name, ...
// data.response will contain the server response
});
}
});
おまけの質問に関する限り、私はセッションを使用しないことで喜んで答えます。セッションはうまくスケーリングしないためですが、おそらくこの答えが気に入らないことがわかっているので、セッションに合格する可能性がありますを使用したリクエストの id multipart_params
:
multipart_params: {
ASPSESSID: '@Session.SessionID'
},
次に、サーバーでいくつかのハックを実行して、適切なセッションを作成します。