【问题标题】:Getting the uploading file name before upload with jQuery File Upload plugin使用 jQuery File Upload 插件在上传前获取上传文件名
【发布时间】:2014-04-24 10:16:39
【问题描述】:

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

谢谢。

【问题讨论】:

    标签: jquery jquery-file-upload


    【解决方案1】:

    好的,这是可行的解决方案:

    // 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};
    });
    

    【讨论】:

      【解决方案2】:
      var filename = $('input[type=file]').val().split('\\').pop();
      

      【讨论】:

        【解决方案3】:

        我不知道您的网站使用了哪种网络服务,如果是 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);
            });
        }
        

        });

        【讨论】:

        猜你喜欢
        • 2015-09-02
        • 2019-11-09
        • 2020-12-08
        • 1970-01-01
        • 2015-03-02
        • 1970-01-01
        • 1970-01-01
        • 2017-02-03
        • 2013-08-01
        相关资源
        最近更新 更多