1
votes

I got response data from the web services, which is base64binary data. I want to load this base64binary data into web view for titanium alloy [version 3.1.0.2]. The data base64binary is of pdf file.

Ti.API.info('Status  is ::',xhrDocument.status);
var ResponseData = xhrDocument.getResponseXML().getElementsByTagName('GetDocResult').item(0).text;  
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'pdfbinarray.pdf');
if(xhrDocument.status == 200){ 
    var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'filename2.pdf');                   file.write(xhrDocument.getResponseXML().getElementsByTagName('GetDocResult').item(0).text);
                              Titanium.API.info('file write');
                              Titanium.API.info(file.size);
}

The above code created filename2.pdf in my Documents directory. When I open the file using Adobe Reader, it says Adobe Reader could not open filename2.pdf because it is either not a valid file or has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

1

1 Answers

0
votes

Is the web service call returning ONLY the document, or is there additional data included in the response?

We have had success using a simpler method. If the service is simply returning the document, try changing line two to something more like this:

    var ResponseData =  xhrDocument.responseText;