capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

Camera image error

Open oliverandersencox opened this issue 8 years ago • 4 comments

Recently, presume because of the update, the local webpath for images from the Camera or file system using capacitor are not displaying in the simulator or device. Below I have logged the image object passed back by capacitor and the error that follows:

[log] - IMAGE RESULT: {"path":"file:///Users/oliverandersen/Library/Developer/CoreSimulator/Devices/69BF3930-3CE6-43F7-86F6-0FA121AB19FC/data/Containers/Data/Application/784DD3F3-C16C-4380-8A4C-B8A4456D3999/tmp/photo-1.jpg","format":"jpeg","exif":{},"webPath":"capacitor-asset:///Users/oliverandersen/Library/Developer/CoreSimulator/Devices/69BF3930-3CE6-43F7-86F6-0FA121AB19FC/data/Containers/Data/Application/784DD3F3-C16C-4380-8A4C-B8A4456D3999/tmp/photo-1.jpg"}

2018-12-02 18:05:46.072316+0000 App[65800:4726806] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

a few days ago this was not an issue, and the images displayed fine on device and simulator.

I may add, in the browser, everything is fine

oliverandersencox avatar Dec 02 '18 18:12 oliverandersencox

Can you provide your code?

Also, in which device and iOS version are you testing?

jcesarmobile avatar Dec 02 '18 19:12 jcesarmobile

Tested on iphone 8 and 7 plus as well as a few device simulators - none work and just display the small blue square with question mark in, or nothing at all

`async takePicture() {
    try {
      const image = await Camera.getPhoto({
        quality: 50,
        allowEditing: true,
        resultType: CameraResultType.Uri,
        correctOrientation: true
      });

      console.log('IMAGE RESULT: ', image);

      this.images.push(image);

    } catch (error) {
      console.log(error);
    }`

Then in my HTML i simple have:

`<div class="edit-image" *ngFor="let image of images; let i = index;">
            <img [src]="image.webPath" />
</div>`

It only started happening this weekend. Ive tried downgrading capacitor, to no effect.

As i said, on web it works absolutely fine. It's just on device and simulator, the image will not render. However when I extract the path and then get the file blob for uploading, this works absolutely fine.

oliverandersencox avatar Dec 02 '18 22:12 oliverandersencox

I'm seeing this error on iPhoneX device today. I was expecting the image to fail when it's upload to cloud. However image does get uploaded OK. Writing a catch for this error until something better. My assumption is config.xml settings and/or conflict with Info.plist settings. Some setting somewhere.

tekknikk avatar Dec 04 '18 05:12 tekknikk

This is an Angular "feature", it adds "unsafe:" to the image urls, which makes them to not load.

You can use DomSanitizer to remove those "unsafe" prefixes.

import { DomSanitizer } from '@angular/platform-browser';

add private sanitizer: DomSanitizer to the constructor

and use it on the src.

<img [src]="this.sanitizer.bypassSecurityTrustResourceUrl(image.webPath)" />

Or you can also configure Angular to allow capacitor, capacitor-asset and capacitor-content schemes so you don't have to sanitize them.

https://stackoverflow.com/questions/15606751/angularjs-changes-urls-to-unsafe-in-extension-page (see the answers about imgSrcSanitizationWhitelist)

jcesarmobile avatar Dec 04 '18 12:12 jcesarmobile