BlueImp / jQuery的文件上传 [英] BlueImp/jQuery file upload

查看:87
本文介绍了BlueImp / jQuery的文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我开发一个应用程序ASP.NET/C#。我使用的 BlueImp文件上传以尝试将文件上传到我的ASHX处理程序。一切工作正常。什么ASHX处理程序做的是它存储在SQL Server数据库中的图像。

I have a ASP.NET/C# application that I am developing. I am using BlueImp File Uploader to try to upload a file to my ASHX handler. Everything is working fine. What the ASHX handler is doing is its storing the image in a SQL Server database.

我的问题是,当我处理程序被执行,它需要与它一起的ID传递,所以它知道哪些记录存储在图像。现在,我的形式为所有的客户端/ AJAX,所以没有回发。我想如果可能的话,以保持这种方式。

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. I'd like to keep it that way, if possible.

下面是code我使用调用处理程序:

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 + '%'
                );
            }
        });

我的ID,现在,被保存在一个隐藏分区。我可以访问它像这样:

My ID, right now, is stored in a hidden div. I can access it like so:

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

我如何通过这个ID到我的ASHX处理程序?我知道我可以将它传递与网址参数的查询参数,但它似乎Blueimp不允许您动态更改URL。一旦它的设置,它似乎永远设置。任何想法?

How do I pass this ID onto my ASHX handler? 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. Once its set, it seems to be set forever. Any ideas?

推荐答案

您可以使用的 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;
    }
});

这篇关于BlueImp / jQuery的文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆