1

我正在尝试使用 plupload JqueryUI Widget 上传器并尝试使用会话 ID 上传图像并且它保存在相应的会话 ID 下但是当在 completeAll (即当我绑定它们时)事件时我试图使用相同的会话 ID 显示它们的文件名不是正在发生。

谁能告诉我我做错了什么?

这是我的代码:

       <script type="text/javascript">
                 $(function () {
           $("#uploader").plupload({
               runtimes: 'gears,flash,silverlight,browserplus,html5',
               url: 'upload.aspx',
               max_file_size: '10mb',
               chunk_size: '1mb',
               unique_names: true,

               // Resize images on clientside if we can
               resize: { width: 320, height: 240, quality: 90 },

               // Specify what files to browse for
               filters: [
            { title: "Image files", extensions: "jpg,gif,png" },
            { title: "Zip files", extensions: "zip" }
        ],

               // Flash settings
               flash_swf_url: 'js/plupload.flash.swf',

               // Silverlight settings
               silverlight_xap_url: 'js/plupload.silverlight.xap'
           });


           // Client side form validation
           $('form').submit(function (e) {
               var uploader = $('#uploader').plupload('getUploader');

               // Files in queue upload them first
               if (uploader.files.length > 0) {
                   // When all files are uploaded submit form
                   uploader.bind('StateChanged', function () {
                       if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                           $('form')[0].submit();
                       }
                   });

                   uploader.start();
               } else
                   alert('You must at least upload one file.');

               return false;
           });

           var uploader = $('#uploader').plupload('getUploader');
           uploader.bind('FileUploaded', function (up, file, res) {
             $('#showfilelist').append("<div id=" + file.id + "><a href='uploads/" & Session("ID") &  "/" + file.name + "'><br>" + file.name + "</div>");

           });
       });
</script>

这是处理程序文件:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If IsNothing(Request.Form("chunk")) = False Then
        If Session("ID") Is Nothing Then
            Session("ID") = Guid.NewGuid.ToString
            IO.Directory.CreateDirectory(Server.MapPath("uploads/" & Session("ID")))
        End If
        Dim chunk As Integer = Request.Form("chunk")
        Dim chunks As Integer = Request.Form("chunks")
        Dim filename As String = Request.Form("name")
        If chunk = 0 Then
            Request.Files(0).SaveAs(Server.MapPath("uploads/") & Session("ID") & "/" & Request.Files(0).FileName)
        Else
            Dim OutputStream As New IO.FileStream(Server.MapPath("uploads/") & Session("ID") & "/" & Request.Files(0).FileName, IO.FileMode.Append)
            Dim InputBytes(Request.Files(0).ContentLength) As Byte
            Request.Files(0).InputStream.Read(InputBytes, 0, Request.Files(0).ContentLength)
            OutputStream.Write(InputBytes, 0, InputBytes.Length - 1)
            OutputStream.Close()
        End If
    End If
End Sub

在此处显示文件名:

<div id="showfilelist">
    </div>
4

2 回答 2

2

我必须承认我不是那么熟悉plupload。但是对于 Uploadify,会话 id 没有传回的原因是因为 flash 没有传回会话 cookie。

SORRY EDIT(新链接,旧链接存在安全漏洞)

这里有一些可以帮助你的东西:

上传 ashx 文件 Context.Session 为空

于 2011-10-12T09:55:25.733 回答
1

我对 plupload 不熟悉,但我发现您的 javascript 中肯定存在问题。检查这个特定的片段:

var uploader = $('#uploader').plupload('getUploader');
uploader.bind('FileUploaded', function (up, file, res) {
     $('#showfilelist').append("<div id=" + file.id + "><a href='uploads/" & Session("ID") &  "/" + file.name + "'><br>" + file.name + "</div>");
});

即代码部分+ "><a href='uploads/" & Session("ID") & "/" +不是有效的java-script 代码。除了不正确的&操作员之外,您无法真正在客户端访问服务器端会话。

我相信正确的解决方案将涉及Session("ID")在您的处理程序的响应中返回您的服务器端 id ()。您可能可以通过事件处理程序的res参数访问响应。FileUploaded

于 2011-10-12T11:34:12.777 回答