Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a full working example I wrote for you:</p> <pre><code>&lt;%@ Page Title="Home Page" Language="C#" %&gt; &lt;%@ Import Namespace="System.IO" %&gt; &lt;script runat="server" type="text/c#"&gt; protected void Page_Load(object sender, EventArgs e) { // Check to see whether there are uploaded files to process them if (Request.Files.Count &gt; 0) { int chunk = Request["chunk"] != null ? int.Parse(Request["chunk"]) : 0; string fileName = Request["name"] != null ? Request["name"] : string.Empty; HttpPostedFile fileUpload = Request.Files[0]; var uploadPath = Server.MapPath("~/TicketUploads"); using (var fs = new FileStream(Path.Combine(uploadPath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append)) { var buffer = new byte[fileUpload.InputStream.Length]; fileUpload.InputStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, buffer.Length); } } } &lt;/script&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt; &lt;head id="Head1" runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;style type="text/css"&gt;@import url(css/plupload.queue.css);&lt;/style&gt; &lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; google.load("jquery", "1.3"); &lt;/script&gt; &lt;script type="text/javascript" src="/plupload/js/gears_init.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/plupload/js/plupload.full.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/plupload/js/jquery.plupload.queue.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function() { $("#uploader").pluploadQueue({ // General settings runtimes : 'gears,flash,silverlight,browserplus,html5', url : '/default.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 : '/plupload/js/plupload.flash.swf', // Silverlight settings silverlight_xap_url : '/plupload/js/plupload.silverlight.xap' }); // Client side form validation $('form').submit(function(e) { var uploader = $('#uploader').pluploadQueue(); // Validate number of uploaded files if (uploader.total.uploaded == 0) { // Files in queue upload them first if (uploader.files.length &gt; 0) { // When all files are uploaded submit form uploader.bind('UploadProgress', function() { if (uploader.total.uploaded == uploader.files.length) $('form').submit(); }); uploader.start(); } else alert('You must at least upload one file.'); e.preventDefault(); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="Form1" runat="server"&gt; &lt;div id="uploader"&gt; &lt;p&gt;You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.&lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>As you will see in this example files are uploaded to the same page called <code>default.aspx</code>. Notice that parameters such as <code>chunk</code> and <code>name</code> are POSTed so you shouldn't use <code>Request.QueryString</code> to read them but <code>Request["chunk"]</code> directly as this will look at the POST body as well. You should also make sure that the <code>TicketUploads</code> folder exists on the server at the root.</p> <p>In this example the same page default.aspx is used for showing the upload form and handling the uploads. In a real world application this is not something I would do. I would recommend you using a separate script which will handle the file uploads such as a generic http handler (upload.ashx).</p> <p>Finally you will notice that I have used some default settings that you might wish to modify and reconfigure the plugin to fit your needs. I just took the settings from the documentation.</p> <hr> <p>UPDATE:</p> <p>And since I recommended using a separate generic http handler for handling the file uploads here's how it might look :</p> <pre><code>using System.IO; using System.Web; public class Upload : IHttpHandler { public void ProcessRequest(HttpContext context) { int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0; string fileName = context.Request["name"] != null ? context.Request["name"] : string.Empty; HttpPostedFile fileUpload = context.Request.Files[0]; var uploadPath = context.Server.MapPath("~/TicketUploads"); using (var fs = new FileStream(Path.Combine(uploadPath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append)) { var buffer = new byte[fileUpload.InputStream.Length]; fileUpload.InputStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, buffer.Length); } context.Response.ContentType = "text/plain"; context.Response.Write("Success"); } public bool IsReusable { get { return false; } } } </code></pre> <p>Now all that's left is to reconfigure the plugin to point to this generic handler:</p> <pre><code>... runtimes: 'gears,flash,silverlight,browserplus,html5', url: '/upload.ashx', max_file_size: '10mb', ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload