cyc*_*ero 6 jquery jquery-file-upload
我正在使用jQuery文件上传插件https://github.com/blueimp/jQuery-File-Upload/wiki将多个文件上传到服务器.我将使用自定义Web服务将上传的图像存储在服务器上.但是,除了POST请求主体之外,我还需要将正在上载的文件的名称传递给Web服务.因此,对于每个文件传输,我还需要将该文件的名称传递给Web服务.有人可以告诉我如何获取文件名并将其与每个上传请求一起发送?我基本上需要从现场获取它,没有任何额外的输入字段.如果用户选择了10个文件,我需要为队列中的每个文件取名,并使用上传请求提交.
谢谢.
cyc*_*ero 12
好的,这是有效的解决方案:
// 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};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31025 次 |
| 最近记录: |