以下爲我工作:
[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
});
}
});
至於獎金問題而言,我願意回答它通過不使用會話,因爲他們不能很好地擴展,但因爲我知道你可能不會喜歡這個答案,所以你可以在請求中使用multipart_params
:
然後在服務器perform some hacks上創建適當的會話。
只是出於好奇,你會怎樣用來代替會議?舉個例子,就我個人而言,我只是爲了獲取登錄用戶而使用它。 – Dynde 2011-05-23 09:53:57
@Dynde,這取決於我願意實施的場景。例如,獲取登錄用戶名我會使用表單身份驗證Cookie => User.Identity.Name,如果我需要登錄用戶信息,我會查詢配置文件服務,它會從我的應用程序保留它的任何地方獲取此信息(通常是一個數據庫)。 – 2011-05-23 09:58:30
我聽到你的聲音。對我來說,配置文件查詢只是可以避免與會話,因爲直到今天我不知道使用會話這是一個壞主意:) – Dynde 2011-05-23 10:19:31