I am trying to show the user's photo in my ionic/cordova application using the img tag as follows,
我试图使用img标签在我的ionic / cordova应用程序中显示用户的照片,如下所示,
<img src="ftp://10.132.21.100/PatientPhoto/Temp_emp.jpg" alt="no image"/>
The image is not getting displayed in the APP (failed to load the resource error). But I can view the image if I enter the same URL(ftp://10.132.21.100/PatientPhoto/Temp_emp.jpg) in my android mobile browser. I am running the debug build, so I guess it is not a permission issue. I have done white listing by adding the below line in the config.xml file,
图像未显示在APP中(无法加载资源错误)。但是如果我在Android手机浏览器中输入相同的URL(ftp://10.132.21.100/PatientPhoto/Temp_emp.jpg),我可以查看图像。我正在运行调试版本,所以我猜这不是一个权限问题。我通过在config.xml文件中添加以下行来完成白名单,
<access origin="*"/>
I tried adding below lines too without any success,
我尝试添加下面的行也没有任何成功,
<allow-intent href="ftp://*/*" />
<allow-navigation href="ftp://*/*" />
Also added Content-Security-Policy to the html file as follows, still facing the same issue.
还向Html文件添加了Content-Security-Policy,如下所示,仍然面临同样的问题。
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
It is working if I a use http URL for img src. The images are stored in the ftp server, so I can't use http URL. Any suggestion is highly appreciated.
如果我使用http URL作为img src,它正在工作。图像存储在ftp服务器中,因此我无法使用http URL。任何建议都非常感谢。
4 个解决方案
#1
2
You need to install cordova whitelist plugin and to config your config.xml
file.
您需要安装cordova whitelist插件并配置config.xml文件。
Please add the following tag: <allow-intent href="ftp://*/*" />
请添加以下标记:
or if you want to allow everything: <access origin="*">
或者如果你想允许一切:
#2
2
You can try to modify your src attribute like this:
您可以尝试修改您的src属性,如下所示:
<img src="ftp://yourusername:yourpassword@10.132.21.100/PatientPhoto/Temp_emp.jpg"/>
it will work but you'd be giving everyone your ftp password.do not use this on a live website
它会工作,但你会给每个人你的ftp密码。不要在现场网站上使用它
#3
0
Have you got a Content Security Policy header:
您是否拥有内容安全策略标头:
<meta http-equiv="Content-Security-Policy"
You'll need this on the page(s) that the image is displayed on.
您需要在显示图像的页面上显示此信息。
See the following link for pointers: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/#content-security-policy
请参阅以下链接以获取指示:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/#content-security-policy
#4
0
< img src="ftp://10.132.21.100/PatientPhoto/Temp_emp.jpg">
Give src between " " and Make sure your server is running
在“”之间提供src并确保您的服务器正在运行
#1
2
You need to install cordova whitelist plugin and to config your config.xml
file.
您需要安装cordova whitelist插件并配置config.xml文件。
Please add the following tag: <allow-intent href="ftp://*/*" />
请添加以下标记:
or if you want to allow everything: <access origin="*">
或者如果你想允许一切:
#2
2
You can try to modify your src attribute like this:
您可以尝试修改您的src属性,如下所示:
<img src="ftp://yourusername:yourpassword@10.132.21.100/PatientPhoto/Temp_emp.jpg"/>
it will work but you'd be giving everyone your ftp password.do not use this on a live website
它会工作,但你会给每个人你的ftp密码。不要在现场网站上使用它
#3
0
Have you got a Content Security Policy header:
您是否拥有内容安全策略标头:
<meta http-equiv="Content-Security-Policy"
You'll need this on the page(s) that the image is displayed on.
您需要在显示图像的页面上显示此信息。
See the following link for pointers: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/#content-security-policy
请参阅以下链接以获取指示:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/#content-security-policy
#4
0
< img src="ftp://10.132.21.100/PatientPhoto/Temp_emp.jpg">
Give src between " " and Make sure your server is running
在“”之间提供src并确保您的服务器正在运行