简体   繁体   English

BlueImp / jQuery文件上传

[英]BlueImp/jQuery file upload

I have a ASP.NET/C# application that I am developing. 我有一个正在开发的ASP.NET/C#应用程序。 I am using BlueImp File Uploader to try to upload a file to my ASHX handler. 我正在使用BlueImp File Uploader尝试将文件上传到我的ASHX处理程序。 Everything is working fine. 一切正常。 What the ASHX handler is doing is its storing the image in a SQL Server database. ASHX处理程序正在做的是将映像存储在SQL Server数据库中。

My problem is, when my handler gets executed, it needs to pass along an ID with it, so it knows what record to store the image in. Right now, my form is all client side/ajax, so there are no postbacks. 我的问题是,当我的处理程序执行时,它需要传递一个ID,以便它知道将图像存储在哪个记录中。现在,我的表单是所有客户端/ ajax,因此没有回发。 I'd like to keep it that way, if possible. 如果可能的话,我想保持这种状态。

Here is the code I'm using to call the handler: 这是我用来调用处理程序的代码:

         $('#fileupload').fileupload({
            url: 'W9UploadHandler.ashx',
            dataType: 'json',
            done: function (e, data) {
                $.each(data.result.files, function (index, file) {
                    $('<p/>').text(file.name).appendTo('#files');
                });
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .bar').css(
                    'width',
                    progress + '%'
                );
            }
        });

My ID, right now, is stored in a hidden div. 我的ID现在存储在一个隐藏的div中。 I can access it like so: 我可以这样访问它:

var id = $('#divHostApplicationId').text();

How do I pass this ID onto my ASHX handler? 如何将此ID传递到ASHX处理程序? I know I could pass it on as a query parameter with the 'url' parameter, but it seems Blueimp doesn't allow you to dynamically change the url. 我知道我可以将它作为带有“ url”参数的查询参数来传递,但是似乎Blueimp不允许您动态更改URL。 Once its set, it seems to be set forever. 一旦设置,它似乎将永远设置。 Any ideas? 有任何想法吗?

you can use formData : 您可以使用formData

$('#fileupload').bind('fileuploadsubmit', function (e, data) {
    // The example input, doesn't have to be part of the upload form:
    var input = $('#divHostApplicationId');
    data.formData = {example: input.val()};
    if (!data.formData.example) {
      input.focus();
      return false;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM