无法通过 iOS 中的图像选择器插件访问所选图像

No access to selected images via image picker plugin in iOS

我写了一段代码,它从图库中选择一张图片,并在本地将其显示为标签并将其 base64 格式上传到服务器。

它在 android 平台上运行良好,但在 iOS 中存在问题。

有两件事:

1- 我得到的路径类似于

file:///var/mobile/Containers/Data/Application/[some string]/tmp/[a name].jpg

2- 并且标签已配置为允许 "file"s

感谢任何有用的指南。

如果您使用 cordova-plugin-image-picker,您可以设置选项 outputType: 1。这将 return base64 格式的图像。

来自 plugin 存储库:

options = {
    // Android only. Max images to be selected, defaults to 15. If this is set to 1, upon
    // selection of a single image, the plugin will return it.
    maximumImagesCount: int,

    // max width and height to allow the images to be.  Will keep aspect
    // ratio no matter what.  So if both are 800, the returned image
    // will be at most 800 pixels wide and 800 pixels tall.  If the width is
    // 800 and height 0 the image will be 800 pixels wide if the source
    // is at least that wide.
    width: int,
    height: int,

    // quality of resized image, defaults to 100
    quality: int (0-100),

    // output type, defaults to FILE_URIs.
    // available options are 
    // window.imagePicker.OutputType.FILE_URI (0) or 
    // window.imagePicker.OutputType.BASE64_STRING (1)
    outputType: int
};

记得在 returned 字符串前添加 data:image/jpeg;base64,。 然后,例如:

this.imagePicker.getPictures({ 
    maximumImagesCount: 1, 
    width: 800, 
    height: 800, 
    quality: 70, 
    outputType: 1 }) //base64 output
.then((results) => {
    return 'data:image/jpeg;base64,'+results[0]; 
});