Hi Daniel,
We encountered a similar issue with using a web application which generates reports that the user can dynamically change and then export to PDF.
We can not use here UHTTP to download PDF because the request use COOKIES and many other context value.
To keep this functioning by displaying this application in the HTML widget, we have injected some javascript code into the web page which downloads the file, cuts it, encodes it in base 64 and send it to UNIFACE end then create the file wth filedump function.
The solution is not very pretty, slow and the file must not exceed a size .
So as soon as possible we prefer to use HTTP to download files.
Gilles.
Javascript :
downloadFile = function (sUrl) {
var http_request = new XMLHttpRequest();
http_request.onreadystatechange = function () {
if (http_request.readyState == 4) {
var array = new Uint8Array(http_request.response);
createLocalFile(array);
}
}
http_request.open("GET", sUrl, true);
http_request.responseType = 'arraybuffer';
http_request.send();
};
createLocalFile = function (array) {
var len = array.byteLength;
var partOfFile = "";
var file = "HW" + (new Date()).getTime();
window.unifaceTriggers("dumpFile", file, 1, 1, "");
for (var i = 0; i < len; i++) {
partOfFile += String.fromCharCode(array[i]);
if (i % 5e6 == 0 && i > 0) {
window.unifaceTriggers("dumpFile", file, 0, 1, btoa(partOfFile));
partOfFile = "";
}
}
if (partOfFile.length > 0) {
window.unifaceTriggers("dumpFile", file, 0, 1, btoa(partOfFile));
partOfFile = "";
}
window.unifaceTriggers("openLocalFile", "", file);
};
Code uniface :
trigger dumpFile
Params
string pFileName: IN
numeric pNew : IN
string pContent : IN
endParams
Variables
string lDossier
raw content
lineardatetime currentDate
EndVariables
content=$decode("BASE64",pContent)
lDossier=$concat($ldir(),"download\",$processinfo("pid"),"\")
if(pNew==1)
if($lfileexists($concat(lDossier,"/",pFileName))==1)
lfiledelete $concat(lDossier,"/",pFileName)
endif
endif
if(pContent!="")
lfiledump/append/raw Content,$concat(lDossier,"/",pFileName)
endif
end