When users upload files using a standard <input type="file">
element, they expect to be redirected
to the page to which they have submitted files. However, Image Uploader works differently. The
response generated by the page, which is specified with the UploadSettings.ActionUrl
property, is sent back to Image Uploader and not to the browser. In other words, it works as
follows:
What will happen on the last step depends on the settings. By default, no action would be carried out. This is convenient when Image Uploader is inserted into a pop-up window and you would like it to open in the background.
Another popular behavior is to redirect a user to another page which, for example, displays uploaded files. The simplest way to accomplish this is to use the UploadSettings.RedirectUrl property:
<aur:Uploader ID="Uploader1" runat="server"> <UploadSettings ActionUrl="upload.aspx" RedirectUrl="gallery.aspx" /> </aur:Uploader>
$uploader = new Uploader("Uploader1"); $uploader->getUploadSettings()->setActionUrl("upload.php"); $uploader->getUploadSettings()->setRedirectUrl("gallery.php");
var u = $au.uploader({ id: 'Uploader1', uploadSettings: { actionUrl: 'upload.aspx', redirectUrl: 'gallery.aspx' } });
A more complicated but more flexible way of handling the server response is to use the AfterUpload event. It is raised upon successful upload, and using it you can perform any actions allowed in client-side scripting. For instance, you can specify another way of redirecting a user:
function afterUploadHandler(response) { window.location = "gallery.aspx"; } var u = $au.uploader({ id: 'Uploader1', events: { afterUpload: afterUploadHandler } });
You can also get access to the server response returned from the upload processing script. Here we demonstrate how to display a page returned from a server:
function afterUploadHandler(response) { var newWindow = window.open(); with (newWindow.document) { open("text/html"); write(response); close(); } } var u = $au.uploader({ id: 'Uploader1', events: { afterUpload: afterUploadHandler } });