Hi,
I want use an ajax request to download when required a binary file.
The file is a Dicom image (medical format) encoded in 8, 12 or 16 bits.
For the moment I use this code to download the file, and all is correct:
Code:
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
if('SR' == type)
xhr.responseType = 'text';
else if('JPEG' == type)
{
xhr.overrideMimeType('text/plain; charset=x-user-defined');
}
else if('DCM' == type)
xhr.responseType = 'arraybuffer';
var me = this;
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && xhr.status == 200)
{
var data = xhr.response;
if('JPEG' == type)
{
data = "data:image/jpeg;base64," + encode64(xhr.responseText);
}
setLoadedUrl(data, me/*,i*/);
}
}
I'd like use JsExt technology to make the same thing.
I try to use Ext.Ajax.request, but I don't find how to set a good config
Code:
//Ext.Ajax.defaultHeaders = {"Content-Type": '???'};
//Ext.Ajax.defaultHeaders = {"'???'": '???'};
//??? Other settings
Ext.Ajax.request({
url: url
,method: 'GET'
,success: function(response, opts){
//alert("loaded");
if('DCM' == type){
//do something
}
else{
var data = response.responseText;
if('JPEG' == type)
{
data = "data:image/jpeg;base64," + encode64(response.responseText);
}
setLoadedUrl(data, this.model/*,this.urlId*/);
}
}
,scope: {
model: this
,urlId: i
,nbUrl: allUrls.length
}
});
Where
the url can be:
http://localhost/MyApp/data/Bassin.dcm
Bassin.dcm is the Dicom image saved on the server side.
When I use the Ext.Ajax.request, I have only a responseText parameter containing (I think) a base64 string:
US(�!CS�00@���UL����@�USQ������P ...
Response:
HTTP/1.1 200 OK
Date: Fri, 25 May 2012 17:51:43 GMT
Server: Apache/2.2.21 (Win64) PHP/5.3.10
Last-Modified: Sat, 31 Mar 2012 09:58:54 GMT
Etag: "77000000028fee-37aab4-4bc870143aa95"
Accept-Ranges: bytes
Content-Length: 3648180
Keep-Alive: timeout=5, max=93
Connection: Keep-Alive
Content-Type: text/plain
Request:
GET /MyApp/data/Bassin.dcm?_dc=1337968301937 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://localhost/MyApp/viewer.php
There is no php page to catch the request, the url is directly the file to download.
I hope this information can help you to help me.