WebView does not download with "content-disposition"

  1. I’m looking for a way to download or view documents in webview. I have successfully viewed PDF’s in the past using

  2. Google’s online viewer but in this particular case it won’t work. Here’s my issue:

  3. When the webview opens a link (say http://<mydomain.nl>/download.php?docid=2) it sends me the following headers.

Cache-Control:

private
2.
Connection:

Keep-Alive
3.
Content-disposition:

inline; filename=thedesireddoc.pdf
4.
Content-Encoding:

gzip
5.
Content-Length:

22728
6.
Content-Type:

application/pdf
7.
Date:

Fri, 11 Sep 2015 08:26:16 GMT
8.
Expires:

Mon, 26 Jul 1997 05:00:00 GMT
9.
Keep-Alive:

timeout=1, max=100
10.
Pragma:

private
11.
Server:

Apache/2
12.
Set-Cookie:

PHPSESSID=g7aassgtomgscg542afmkqq237; path=/
13.
Vary:

Accept-Encoding,User-Agent
14.
X-Powered-By:

PHP/5.3.29
15.

The webview does absolutely nothing and just fires the “link” and “loaded” events. No page is updated, no file is downloaded. Is there a way to support this?

FYI, I’m using daily build 2015.2702

 

 

Best regards,~Rob

 

Can you post some code?

Rob

-- constructor function instance:OurBrowser() -- create a single instance of the browser self.nativeBrowser = native.newWebView(0, 0, 1, 1) self.nativeBrowser:addEventListener("urlRequest", function(event) instance:webListener(event) end) end -- event listener function instance:webListener(event) print ("in browser listener") if event.url then print( "You are visiting: " .. event.url ) -- Handle URL to document if event.type == "link" and string.match(event.url, "/download.php") then Runtime:dispatchEvent{name=OurBrowser.BROWSER\_DOCUMENT\_EVENT, url = event.url} end end if event.type then print( "The event.type is " .. event.type ) -- print the type of request end if event.errorCode then print( "Error! " .. event.errorMessage) end Runtime:dispatchEvent{name=OurBrowser.BROWSER\_RESPONSE\_EVENT, browserEvent = event} end

I have no access to the server side code. I just wrapped the browser in my own class to have some control over the creation of native objects. The browser works, only it does not do anything when clicking on a link that returns a response with content-disposition (as shown above). I cannot pass an example link since it requires a login session. 

Hope this helps

I’ve reposted this question, but in a more general form and with code and an example. It seems that an Android webview just does not download files… Here’s the new thread: https://forums.coronalabs.com/topic/59788-download-in-webview/

Best regards,

~Rob

Can you post some code?

Rob

-- constructor function instance:OurBrowser() -- create a single instance of the browser self.nativeBrowser = native.newWebView(0, 0, 1, 1) self.nativeBrowser:addEventListener("urlRequest", function(event) instance:webListener(event) end) end -- event listener function instance:webListener(event) print ("in browser listener") if event.url then print( "You are visiting: " .. event.url ) -- Handle URL to document if event.type == "link" and string.match(event.url, "/download.php") then Runtime:dispatchEvent{name=OurBrowser.BROWSER\_DOCUMENT\_EVENT, url = event.url} end end if event.type then print( "The event.type is " .. event.type ) -- print the type of request end if event.errorCode then print( "Error! " .. event.errorMessage) end Runtime:dispatchEvent{name=OurBrowser.BROWSER\_RESPONSE\_EVENT, browserEvent = event} end

I have no access to the server side code. I just wrapped the browser in my own class to have some control over the creation of native objects. The browser works, only it does not do anything when clicking on a link that returns a response with content-disposition (as shown above). I cannot pass an example link since it requires a login session. 

Hope this helps

I’ve reposted this question, but in a more general form and with code and an example. It seems that an Android webview just does not download files… Here’s the new thread: https://forums.coronalabs.com/topic/59788-download-in-webview/

Best regards,

~Rob