I'm currently developping an app with phonegap and I want to update the content of my application which is on wordpress. Through an JSON API, I get the html content of the pages, but the problem is getting the images choose by the user. What I have done, is send a zip from wordpress to my smartphone which contains the new html content, and the new images. I download the zip, apply the new html content, and copy the images inside 'cdvfile://localhost/persistent' which is translate to '/storage/emulated/0/' with phonegap because I use it on a Android phone. I would like to display the images inside an html page but I don't know the link to access to '/storage/emulated/0/' I try the link 'file:///storage/emulated/0/img.png' but nothing appears... any idea? I'm still thinking using imagecache but I'm afraid it will be slower to use it instead of my way...
Asked
Active
Viewed 6,944 times
2 Answers
2
Finally it was due to other error. To show the image inside 'storage/emulated/0/' with phonegap using this :
<img src="cdvfile://localhost/persistent/img/photo-241x300.jpg" alt="">
works well.

user2429082
- 485
- 2
- 7
- 17
-
How would you save the image to folder inside the app? – trainoasis Jun 19 '14 at 09:50
-
Concerning my app I download a zip from a server which contains images and unzip it inside the app – user2429082 Jun 20 '14 at 14:19
-
I'm not sure you understood what I want exactly. If you want you can check this question here http://stackoverflow.com/questions/24300176/phonegap-build-download-image-in-one-of-the-folders-of-your-app (please do :) ) – trainoasis Jun 20 '14 at 18:12
-
@trainoasis I did like you did I register the images in "cdvfile://localhost/persistent/MyAppID/" and it creates a MyAppID folder. Why you don't want to create a folder inside the storage? Do you want to register your images inside your 'www' folder? – user2429082 Jun 23 '14 at 06:58
-
Yes I want them stored in my www folder – trainoasis Jun 23 '14 at 07:16
-
@trainoasis ahah I understand now. Too bad, but I try to do the same and apparently this is impossible, because the folder where your app is create is unreadable. – user2429082 Jun 23 '14 at 07:28
-
Do you have any references about this? :/ ahhh – trainoasis Jun 23 '14 at 07:32
-
@trainoasis Sadly not. But you can see it by your own. Look on the internet where the app is install on Android. And with the DDMS tool in adt you can see the permission of the folder, where your app is install. There is a solution by the way, root your phone :) – user2429082 Jun 23 '14 at 07:43
-
awww. Then I must tell all my users to root theirs too :P. Too bad there's no solution – trainoasis Jun 23 '14 at 07:45
-
@trainoasis there is an other way I think if you are using cordova 3.5 : https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md you can choose other folders to put your images becarefull with the compatibility between ios and Android – user2429082 Jun 23 '14 at 08:02
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/56090/discussion-between-trainoasis-and-user2429082). – trainoasis Jun 23 '14 at 08:06
1
In my case, if using <img src="cdvfile://localhost/persistent/img/my-image.png" alt="">
I get error
Refused to load the image 'cdvfile://localhost/persistent/img/my-image.png' because it violates the following Content Security Policy directive: 'img-src *'.
To resolve this, I change my index.html changing Content-security-policy to
<meta http-equiv="Content-Security-Policy"
content="style-src * 'self' 'unsafe-inline';
font-src * data:;
script-src * 'unsafe-inline' 'unsafe-eval';">
I remove rule default-src * gap://ready file:; img-src * data:;
, now I can use <img src="file:///data/user/0/MY-APP-ID/files/my-image.png">
Warning: My files are saved in cordova.file.dataDirectory

John Henrique
- 324
- 2
- 12