我正在使用ionic 2 native ImagePicker插件
ImagePicker.getPictures({
maximumImagesCount: 1
}).then((results) => {
vm.sourcePath = results[0]
console.log(vm.sourcePath)
// file:///Users/aymanjitan/Library/Developer/CoreSimulator/Devices/E937952F-7FAA-4DBB-8E23-80B04F3B6C72/data/Containers/Data/Application/FCF9097F-67BD-4DAD-AE30-D2F1839C0374/tmp/cdv_photo_003.jpg
})
现在我尝试使用image src属性访问此图像
<img [src]='sourcePath' />
甚至硬编码路径
<img src="file:///Users/aymanjitan/Library/Developer/CoreSimulator/Devices/E937952F-7FAA-4DBB-8E23-80B04F3B6C72/data/Containers/Data/Application/FCF9097F-67BD-4DAD-AE30-D2F1839C0374/tmp/cdv_photo_003.jpg"
但这没有任何表现 .
知道
<apan>{{sourcePath}}</apan>
正确显示路径!
我尝试使用ionic native File plugin将图像转换为base64
var sourceDirectory = vm.sourcePath.substring(0, vm.sourcePath.lastIndexOf('/') + 1);
var sourceFileName = vm.sourcePath.substring(vm.sourcePath.lastIndexOf('/') + 1, vm.sourcePath.length);
File.readAsArrayBuffer(sourceDirectory, sourceFileName).then((fileData)=> {
console.log(fileData)
}, () => {
console.log('error')
})
但是这会引发错误
我在config.xml中添加了这些白名单规则
<access origin="*"/>
<allow-navigation href="*"/>
<allow-navigation href="file://*/*"/>
但仍然没有运气
我虽然可能返回的文件路径不正确所以我把它放在我的浏览器中,它显示了应该选择的图像
那么如何在iOS上使用ionic 2访问本 Map 像(9.3)
1 回答
link中author建议的解决方案的解决方法可以完成
使用
$cordovaFile.readAsDataUrl(„file:///...“, „myPic.png“)
,您可以请求文件的内容 .在
View
<img src=“{{ imgSrc }}“ />
在
controller
并在
config.xml
接下来是你的
index.html
文件From Cordova 4.0.0 for Android's update:
注意:虽然不是此版本的严格部分,但cordova-cli创建的最新默认应用程序默认包含此插件 .
填充归属归于此thread以及链接和上面提到的作者