【问题标题】:No access to selected images via image picker plugin in iOS无法通过 iOS 中的图像选择器插件访问所选图像
【发布时间】:2018-05-23 21:29:45
【问题描述】:

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

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

有两件事:

1- 我得到类似于

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

2- 并且标签已经配置为允许“文件”

感谢任何有用的指南。

【问题讨论】:

    标签: ios ionic-framework plugins ionic-native


    【解决方案1】:

    如果您使用cordova-plugin-image-picker,您可以设置选项outputType: 1。这将返回 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
    };
    

    记得在返回的字符串前加上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]; 
    });
    

    【讨论】:

    • 谢谢。我会试一试,但显然它仍然不能用作图像标签 src atr。有什么想法吗?
    • 使用 [src]="img" 而不是 src="{{ img }}"。您是否尝试过记录结果?
    • 这并没有什么区别,但是“outputType: 1”给了我一个很酷的base64字符串,可以发送到服务器。所以我确定科尔多瓦无法访问本机存储。我不知道如何授予它。
    • 可以通过这个插件ionicframework.com/docs/native/file访问本机存储,但是对于图像拾取我更喜欢base64
    • 我放弃了预览功能。无论如何,谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    相关资源
    最近更新 更多