【发布时间】:2017-02-26 01:38:01
【问题描述】:
我正在使用 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>
正确显示路径!
我尝试使用离子原生 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(9.3) 上使用 ionic 2 访问本地图像
【问题讨论】:
标签: ios ionic-framework cordova-plugins ionic2 ngcordova