I'm working on a Worklight project that downloads a zip file, unpacks it, and stores the files in the specific documents directory of the platform (in iOS that's NSDocumentDirectory
, on Android I'm using getFilesDir()
). The file consists of one HTML file and several images, located in a sub directory (media). Downloading and unzipping works fine on both platforms. After the unzip process I'm loading the contents of the HTML file into an existing div (since this is a Worklight app, everything is in one HTML file).
Here things become complicated:
The image tag sources in the HTML file that I've downloaded are relative to the HTML file (e.g. 'media/myimage.jpg'). When I inject the HTML file into the Worklight HTML file (which is located in the App bundle/package), the base URL changes and the images can't be found anywhere. I fixed this by writing native functions that rewrite all the image tags in the downloaded HTML file to point to an absolute URL (iOS: /var/mobile/Applications/<identifier>/Documents/
, Android: /data/data/<id>/files/
). This works fine on iOS, but on Android it causes the HTML to only load partially. LogCat then shows:
Unknown chromium error: -6
If I keep the files as they are, the HTML loads correctly, but obviously with broken images. I've also tried to change the URLs to file:///data/data/<id>/files/ [...]
, which also causes the HTML to not load completely. I have really no idea what is causing this problem. The app already has the WRITE_EXTERNAL_STORAGE
permission.
Does anyone have an idea how to fix this? Thank you!