Aurigma Image Uploader 6.5 Dual
Preserving Sessions and Authentication Tickets Passed in Cookies
This article describes how to keep session and authentication information saved during upload. In particular, this task is related to passing authentication information by Image Uploader Java in the way used in standard ASP.NET authentication mechanism.
The thing is that Java version of Image Uploader loses HTTP-only cookies when it uploads files to a server. So you should explicitly pass these cookies to the applet before it starts uploading. To do it you should use the AddCookie() method, which accepts cookie name-value pairs separated with semicolon.
The most convenient place to call this method is the BeforeUpload event handler which fires when the upload is about to be started. The code snippet below demonstrates how to attach authentication and session cookies using this method. Note, this sample is for ASP.NET only.
JavaScript
<script type="text/javascript" src="iuembed.js"> </script>
<script language="javascript">
function ImageUploader_BeforeUpload(){
if (iu.getControlType() == "Java")
getImageUploader("ImageUploader").AddCookie(
'<%= FormsAuthentication.FormsCookieName %>=<%=Request.Cookies[FormsAuthentication.FormsCookieName].Value %>;' +
'ASP.NET_SessionId=<%= Request.Cookies["ASP.NET_SessionId"].Value %>');
}
var iu = new ImageUploaderWriter("ImageUploader", 770, 500);
iu.activeXControlEnabled = false;
iu.javaAppletEnabled = true;
//For Java applet we specify only directory with JAR files
iu.javaAppletCodeBase = "./";
iu.showNonemptyResponse = "off";
//Other parameters...
//Configure URL files are uploaded to.
iu.addParam("Action", "upload.aspx");
iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");
iu.writeHtml();
</script>
For PHP server platform you can use the following sample to preserve PHP session:
JavaScript
<script type="text/javascript" src="iuembed.js"> </script>
<script language="javascript">
function ImageUploader_BeforeUpload(){
if (iu.getControlType() == "Java")
getImageUploader("ImageUploader").AddCookie('PHPSESSID=<?=$_COOKIE["PHPSESSID"]?>');
}
var iu = new ImageUploaderWriter("ImageUploader", 770, 500);
iu.activeXControlEnabled = false;
iu.javaAppletEnabled = true;
//For Java applet we specify only directory with JAR files
iu.javaAppletCodeBase = "./";
iu.showNonemptyResponse = "off";
//Other parameters...
//Configure URL files are uploaded to.
iu.addParam("Action", "upload.aspx");
iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");
iu.writeHtml();
</script>