Adds the specified cookie string to the upload request.

Syntax

JavaScript CopyCode imageCopy Code
getImageUploader("ImageUploaderID").AddCookie(Cookie);
Parameters
Cookie
String value that specifies the HTTP-only cookie to attach it to the upload request.

Remarks

Most browsers, such as Firefox since version 2.0.0.5 or Internet Explorer (from version 6 SP1), support HTTP-only cookies. They make it impossible to read these cookies using JavaScript. It increases security and prevents your site from cross-site scripting attacks.

When Java version of Image Uploader prepares the POST request before uploading it to the server, it extracts all cookies which are downloaded along with the page that hosts Image Uploader. To get cookie, Image Uploader uses the same object model as you do in JavaScript (as if you use document.cookie). However the browser does not allow Image Uploader to get HTTP-only cookies. That is why when you post files to the server, it does not get such cookies.

Use the AddCookie method to avoid this problem. It can be used in the BeforeUpload event handler as it shown in the following sample. What you need is to pass to this method a cookie name-value pair as a string, separated with '=' character. Note, this sample is for ASP.NET only.

JavaScript CopyCode imageCopy Code
<script type="text/javascript" src="iuembed.js"></script>                       
 
<script language="javascript">
function ImageUploader_BeforeUpload(){
getImageUploader("ImageUploader").AddCookie('<%=FormsAuthentication.FormsCookieName %>=<%= Request.Cookies[FormsAuthentication.FormsCookieName].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.javaAppletCached = false;
iu.javaAppletVersion = "5.0.10.0";
iu.showNonemptyResponse = "off";

//Other parameters…
               
//Configure URL files are uploaded to.
iu.addParam("Action", "upload.aspx");
iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");
iu.writeHtml();
</script> 
NoteNote

Although you can send traditional cookies this way, you should use it solely for HTTP-only cookies.

See Also

Reference
BeforeUpload Event