使用jQuery File Upload插件在上传之前获取上传文件名

我正在使用jQuery文件上传插件https://github.com/blueimp/jQuery-File-Upload/wiki将多个文件上传到服务器。 我将使用自定义Web服务将上传的图像存储在服务器上。 但是,除了POST请求主体之外,我还需要将正在上载的文件的名称传递给Web服务。 因此,对于每个文件传输,我还需要将该文件的名称传递给Web服务。 有人能告诉我如何获取文件名并将其与每个上传请求一起发送? 我基本上需要从现场获取它,没有任何额外的输入字段。 如果用户选择了10个文件,我需要为队列中的每个文件取名,并使用上传请求提交。

谢谢。

好的,这是有效的解决方案:

// Storing the file name in the queue var fileName = ""; // On file add assigning the name of that file to the variable to pass to the web service $('#fileupload').bind('fileuploadadd', function (e, data) { $.each(data.files, function (index, file) { fileName = file.name; }); }); // On file upload submit - assigning the file name value to the form data $('#fileupload').bind('fileuploadsubmit', function (e, data) { data.formData = {"file" : fileName}; }); 
 var filename = $('input[type=file]').val().split('\\').pop(); 

我不知道你的网站使用什么样的网络服务,简历是ashx,如果你可以使用的话

 HttpPostedFile file = context.Request.Files["Filedata"]; 

获取文件名;

或者使用jquery

 $("#yourid").uploadify({ ..... 'onSelect': function(e, queueId, fileObj) { alert( "FileName:" + fileObj.name); } }); 

// jquery-file-upload

 $('#fileupload').fileupload({ drop: function (e, data) { $.each(data.files, function (index, file) { alert('Dropped file: ' + file.name); }); }, change: function (e, data) { $.each(data.files, function (index, file) { alert('Selected file: ' + file.name); }); } 

});