Vinay B R
Vinay B R

Reputation: 8421

phonegap filesystem url - usage in html image tag

I have recently migrated to phonegap 3.2 and my filetransfer code had to be changed to use toURL() instead of fullPath as per the document. The path returned now looks like cdvfile://localhost/...

I store this path when the file is downloaded from the server for the first time and subsequently use it in all my html pages. The image loads fine when its loaded for the first time but subsequent access fails to load the image.

Upvotes: 1

Views: 1101

Answers (1)

Vinay B R
Vinay B R

Reputation: 8421

I finally got it working. You will have to call getFile to get the file entry and then use the url in the image source. I construct image tags with some default image in the following format-

<img src="default.png?actualimagename"/>

Once this is done i register a script to go through all such images and then do a getFile and replace the image source and that works fine. I am not sure about the logic behind why it is required. I ran into this fix accidentally.

Another issue i found was that fileEntry.toURL() path doesnt work on iOS, i had to use fullPath for iOS and toURL for android.

Upvotes: 3

Related Questions