metadata.cookie Property ActiveX/Java Uploader JavaScript

Supported browsers: FirefoxGoogle ChromeSafari

Gets or sets cookies which should be added to the upload request.

Syntax

JavaScript Initialize
$au.uploader({
    metadata: {
        //...other params...
        cookie: "",
        //...other params...
    }
})
Get/Set Value at Runtime
$au.uploader('uploaderID').metadata().cookie(value);
value = $au.uploader('uploaderID').metadata().cookie();

Property Value

Type: String

The cookie string to attach it to the upload request.

Default value is "".

Remarks

Most browsers, such as Firefox since version 2.0.0.5 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 Uploader prepares the POST request before uploading it to the server, it extracts all cookies downloaded along with the page that hosts ActiveX/Java Uploader. To get cookie, Java Uploader uses the same object model as you do in JavaScript (as if you use document.cookie). However, the browser does not allow Java Uploader to get HTTP-only cookies. That is why when you post files to the server, it does not get such cookies.

Note

ActiveX/Java Uploader ASP.NET and ActiveX/Java Uploader PHP automatically pass the session and authentication information to the upload request.

However, if ActiveX/Java Uploader JavaScript is used, you should add cookies to the upload request manually. To do this, add each cookie you need to preserve via this method as it is shown below.

Example

Preserving cookies in ASP.NET:

JavaScript
var u = $au.uploader({
    id: 'Uploader1',
    metadata: {
        cookie: 'ASP.NET_SessionId=<%=Page.Session.SessionID%>;' +
            '<%=FormsAuthentication.FormsCookieName%>=' + 
            '<%=Request.Cookies[FormsAuthentication.FormsCookieName].Value %>'
    }
}); 

u.writeHtml();

Preserving cookies in PHP:

JavaScript
var u = $au.uploader({
    id: 'Uploader1',
    metadata: {
        cookie: 'PHPSESSID=<?=$_COOKIE["PHPSESSID"]?>'
    }
}); 

u.writeHtml();

See Also

Manual