I want to download a file using a webview. A PDF file in particular. Is this at all possible using a webview? Because all my attempts so far have failed. All I get is a “loaded” event from the webview. But no data or file is downloaded.
I know how to download files using the network.* API, but since the downloadable files are behind a login session and are generated on request, they can, in general, only be reached via a web browser session.
Any ideas would be helpful. I made a test page with several links to a PDF, but none of them can be used for downloading a file within a webview. Here’s the link: https://www.flexuur.com/download.php
Here’s the test code I’ve been using to check if download works. Disregard the “idebug” mention. This is a helper class that contains functions to print out complete contents of a lua table for debugging purposes.
local dbg = require ('idebug') local webview = native.newWebView(display.contentCenterX,display.contentCenterY, display.contentWidth, display.contentHeight) local function webListener( event ) dbg.print\_r( event ) if event.url then print( "You are visiting: " .. event.url ) end if event.type then print( "The event.type is " .. event.type ) -- print the type of request end if event.errorCode then native.showAlert( "Error!", event.errorMessage, { "OK" } ) end end webview:addEventListener( "urlRequest", webListener ) webview:request( "https://www.flexuur.com/download.php" )
Thanks in advance for your help.