Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capacitor Camera throwing "Unable to create photo on disk" #2013

Closed
2 of 7 tasks
nj-coder opened this issue Sep 30, 2019 · 7 comments
Closed
2 of 7 tasks

Capacitor Camera throwing "Unable to create photo on disk" #2013

nj-coder opened this issue Sep 30, 2019 · 7 comments

Comments

@nj-coder
Copy link
Contributor

nj-coder commented Sep 30, 2019

Description of the problem:
The camera plugin works great on Android 8+ devices, but for some reason, it throws the below error on a Samsung Tab A(SM-T280)
image
Affected platform

  • Android
  • iOS
  • electron
  • web

OS of the development machine

  • Windows
  • macOS
  • linux

Other information:

Capacitor version: 1.2.1

node version: 10.16.3

npm version: 6.11.3

Steps to reproduce:

  1. Configure the camera plugin as below on an Android 5 device
const image = await Plugins.Camera.getPhoto({
      quality: 100,
      allowEditing: false,
      resultType: CameraResultType.Base64,
      source: CameraSource.Camera
    });
  1. Try opeing camera on the devices and check console for potential errors.

Logcat

10-01 12:42:20.799 20455-20642/com.uglunipart D/Capacitor/CameraUtils: Trying to save image to public external directory
10-01 12:42:50.288 20455-20642/com.uglunipart E/Capacitor/Plugin: Unable to create photo on disk
    java.io.IOException: open failed: ENOENT (No such file or directory)
        at java.io.File.createNewFile(File.java:944)
        at java.io.File.createTempFile(File.java:1009)
        at com.getcapacitor.plugin.camera.CameraUtils.createImageFile(CameraUtils.java:34)
        at com.getcapacitor.plugin.Camera.openCamera(Camera.java:199)
        at com.getcapacitor.plugin.Camera.showCamera(Camera.java:129)
        at com.getcapacitor.plugin.Camera.doShow(Camera.java:90)
        at com.getcapacitor.plugin.Camera.getPhoto(Camera.java:81)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
        at com.getcapacitor.Bridge$2.run(Bridge.java:529)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:145)
        at android.os.HandlerThread.run(HandlerThread.java:61)
     Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Posix.open(Native Method)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
        at java.io.File.createNewFile(File.java:937)
        at java.io.File.createTempFile(File.java:1009) 
        at com.getcapacitor.plugin.camera.CameraUtils.createImageFile(CameraUtils.java:34) 
        at com.getcapacitor.plugin.Camera.openCamera(Camera.java:199) 
        at com.getcapacitor.plugin.Camera.showCamera(Camera.java:129) 
        at com.getcapacitor.plugin.Camera.doShow(Camera.java:90) 
        at com.getcapacitor.plugin.Camera.getPhoto(Camera.java:81) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
        at com.getcapacitor.Bridge$2.run(Bridge.java:529) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:145) 
        at android.os.HandlerThread.run(HandlerThread.java:61) 
10-01 12:42:50.288 20455-20642/com.uglunipart D/Capacitor: Sending plugin error: {"save":false,"callbackId":"22237336","pluginId":"Camera","methodName":"getPhoto","success":false,"error":{"message":"Unable to create photo on disk"}}
10-01 12:42:50.308 20455-20455/com.uglunipart E/Capacitor/Console: File: http://localhost/main-es2015.a5ca47b02acd21cd4cd6.js - Line 1 - Msg: ERROR Error: Uncaught (in promise): Object: {"message":"Unable to create photo on disk"}
@nj-coder
Copy link
Contributor Author

nj-coder commented Oct 1, 2019

UPDATE: issue happens only when saveToGallery is set to true

@yigitbacakoglu
Copy link

Error still continues in the latest versions, any update?

@Xdabier
Copy link

Xdabier commented Aug 11, 2020

Error still continues in the latest versions, any update?

Same here running on: {
"@capacitor/cli": "2.3.0",
"@angular/cli": "~9.1.5",
"@capacitor/android": "^2.3.0",
"@capacitor/core": "2.3.0",
"@ionic/angular": "^5.0.0",

}

@hembachrterran
Copy link

hembachrterran commented Apr 30, 2021

What's the solution to this error? Still exists with "@capacitor/core": "^2.4.0" and "@capacitor/android": "^2.4.7", "@ionic-native/camera": "^5.32.1".

@mtpultz
Copy link

mtpultz commented Jun 16, 2021

@hembachrterran were you able to resolve this issue? I have this issue now in our Ionic 5 application using the same version as you are.

@hembachrterran
Copy link

As I remember this problem was solved by ask CAMERA permission in app.component.ts:

constructor(public androidPermissions:AndroidPermissions)
{
this.androidPermissions.requestPermissions([
      this.androidPermissions.PERMISSION.CAMERA,
      this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE,
      this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE,]);

and you have to add android:requestLegacyExternalStorage="true" and

<!-- Camera, Photos, input file -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

to AndroidManifest.xml.

Pay attention to the target Android version in your app, after Android 10 (API level 29) was a storage update in Android, and you can not use the requestLegacyExternalStorage variable with higher target level, more info:
https://developer.android.com/about/versions/11/privacy/storage

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 12, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants