【发布时间】:2018-03-02 04:43:49
【问题描述】:
我一直在努力解决这个问题。我需要将参数传递给 ashx 以进行文件上传。我正在为此使用blueimp。我在许多不同的帖子中看到我将使用“formData”参数来完成此操作,但我不知道在通用处理程序中如何访问信息。这是我用来发布到处理程序的代码:
$(document).ready(function () {
$('#btnFileUpload').fileupload({
url: 'FileUploader.ashx?upload=start',
//This is what I want
//-----------------------
formData: {filename: document.getElementById("txtContractUploadName").value},
//-----------------------
add: function (e, data) {
$('#progressbar').show();
data.submit();
},
progress: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progressbar div').css('width', progress + '%');
},
success: function (response, status) {
$('#progressbar').hide();
$('#progressbar div').css('width', '0%');
console.log('success', response);
switch (response.toLowerCase()) {
case "success":
ShowNotificationBar('Success!', 1000, 'notificationSuccess');
break;
case "file size":
ShowNotificationBar('You may only upload files that are 5MB or less.', 2500, 'notificationFail');
break;
case "file type":
ShowNotificationBar('You may only upload PDF files.', 2000, 'notificationFail');
break;
}
},
error: function (error) {
$('#progressbar').hide();
$('#progressbar div').css('width', '0%');
ShowNotificationBar('There was an error with your request.', 2000, 'notificationFail');
}
});
});
进入 C# 处理程序后,如何获取“文件名”?
public void ProcessRequest(HttpContext context)
{
//What do I do here?
}
谢谢。
【问题讨论】:
标签: c# jquery file-upload generic-handler