Xzya
Xzya

Reputation: 347

Cordova InAppBrowser download file from JSP page

I have an app which opens an external website in InAppBrowser. The website is using Java Server Pages and Java Server Faces. I want to detect when the user wants to download a file and prompt him with the intent chooser/download the file/open the file in Chrome.

The problem is that nothing happens when I click on a file, I tried adding a DownloadListener as well, but it's never called. The urls don't contain any extension, so I can't detect it by that, instead, all requests are made by a POST to the current page with some form data, and the response has the headers:

Content-Disposition:attachment;filename=somefilename.xlsx
Content-Type:application/octet-stream
Transfer-Encoding:chunked
X-FRAME-OPTIONS:SAMEORIGIN
X-Powered-By:Servlet/3.0 JSP/2.2
X-Powered-By:JSF/2.0  

I can't find any way to get this working. On iOS the file opens in a new page, just like it would in the browser, but on Android nothing happens.

I must use InAppBrowser because the role of the app is to provide an app for an existing website, and using an iframe is not a solution because they don't allow cross origin requests.

Update
This is how the download link looks like:

<form id="j_idt181:0:j_idt196" name="j_idt181:0:j_idt196" method="post" action="/somepathhere/portal.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt181:0:j_idt196" value="j_idt181:0:j_idt196">
    <a href="#" onclick="something.jsfcljs(document.getElementById('j_idt181:0:j_idt196'),{'j_idt181:0:j_idt196:j_idt197':'j_idt181:0:j_idt196:j_idt197'},'');return false">
        <img src="/somepathhere/javax.faces.resource/excel.png.xhtml?ln=img" style="width:30px; height: 30px; " title="Download">
            Download
        </img>
        <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-5463575505694988987:906233489912842961" autocomplete="off">
        </input>
    </a>
</input>

Upvotes: 0

Views: 835

Answers (1)

johnborges
johnborges

Reputation: 2533

You cannot download files through the InAppBrowser. I would suggest trying to use a plugin like the File Transfer Plugin to asynchronously download the file through the app. I'm guessing that the JSP site you're hitting is using <input type="file />" which doesn't really work with mobile.

Upvotes: 0

Related Questions