Search code examples
imagehttpextjsbasic-authentication

Sencha Touch 2 Images on server with Basic Authentication


I've a problem on Sencha with images which come from server with Basic Authentication, indeed images don't want to show on Android device (Galaxy S2) in tpl, I've tried to put an URL like this [http://username:password@mydomain/image.png] in the src of the image but it doesn't work.

I've also tried send an Ajax request with the identifiers in header but it's the same result.

Can you help me please ? Do you have any other solution ?

Thank you.


Solution

  • Finally, I've resolved my problem. I've used XMLHttpRequest with an header.

    var xhr = new XMLHttpRequest();
    xhr.open('GET', myURL, false);
    xhr.setRequestHeader('Authorization', 'Basic '+base64ArrayBuffer(username+':'+password));
    xhr.overrideMimeType('text/plain; charset=x-user-defined');
    xhr.send(null);
    

    I've converted xhr.responseText in base64 with the function base64ArrayBuffer and put it in the src of my image and it's work.

    I've find the code of the function base64ArrayBuffer here : Retrieving binary file content using Javascript, base64 encode it and reverse-decode it using Python