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();

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 Image Uploader prepares the POST request before uploading it to the server, it extracts all cookies 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.

Note

Image Uploader ASP.NET and Image Uploader PHP automatically pass the session and authentication information to the upload request.

However, if Image 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();