Phonegap display images with the path 'cdvfile://localhost/persistent'

删除回忆录丶 提交于 2020-01-16 03:26:49

问题


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...


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/23784480/phonegap-display-images-with-the-path-cdvfile-localhost-persistent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!