spoonconsulting / cordova-plugin-background-upload

Cordova plugin for background upload
Apache License 2.0
51 stars 54 forks source link

File not found since Capacitor 5 #273

Open rudyZanotti opened 1 year ago

rudyZanotti commented 1 year ago

Hello,

Since I updated my dependencies, uploading video gives a file not found on my app.

doWork: File not found !
 java.io.FileNotFoundException: /__cdvfile_files-external__/files/videos/bc6e7359-db44-4629-9e91-dd8719ef7e05-1694270541591.mp4: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:574)
    at java.io.FileInputStream.<init>(FileInputStream.java:160)
    at com.spoon.backgroundfileupload.UploadTask.createRequest(UploadTask.java:345)
    at com.spoon.backgroundfileupload.UploadTask.doWork(UploadTask.java:178)
    at androidx.work.Worker$1.run(Worker.java:82)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
    at java.lang.Thread.run(Thread.java:1012)
 Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8063)
    at libcore.io.IoBridge.open(IoBridge.java:560)
    at java.io.FileInputStream.<init>(FileInputStream.java:160) 
    at com.spoon.backgroundfileupload.UploadTask.createRequest(UploadTask.java:345) 
    at com.spoon.backgroundfileupload.UploadTask.doWork(UploadTask.java:178) 
    at androidx.work.Worker$1.run(Worker.java:82) 

My package.json

    "@angular/common": "^16.2.4",
    "@angular/core": "^16.2.4",
    "@angular/forms": "^16.2.4",
    "@angular/platform-browser": "^16.2.4",
    "@angular/platform-browser-dynamic": "^16.2.4",
    "@angular/router": "^16.2.4",
    "@awesome-cordova-plugins/android-permissions": "^6.0",
    "@awesome-cordova-plugins/background-upload": "^6.4",
    "@awesome-cordova-plugins/badge": "^6.0",
    "@awesome-cordova-plugins/camera": "^6.0",
    "@awesome-cordova-plugins/clipboard": "^6.0",
    "@awesome-cordova-plugins/core": "^6.0",
    "@awesome-cordova-plugins/file": "^6.0",
    "@awesome-cordova-plugins/file-path": "^6.0",
    "@awesome-cordova-plugins/file-transfer": "^6.0",
    "@awesome-cordova-plugins/globalization": "^6.0",
    "@awesome-cordova-plugins/http": "^6.0",
    "@awesome-cordova-plugins/insomnia": "^6.0",
    "@awesome-cordova-plugins/instagram": "^6.0",
    "@awesome-cordova-plugins/open-native-settings": "^6.0",
    "@awesome-cordova-plugins/screen-orientation": "^6.0",
    "@awesome-cordova-plugins/social-sharing": "^6.0",
    "@awesome-cordova-plugins/splash-screen": "^6.0",
    "@awesome-cordova-plugins/status-bar": "^6.0",
    "@awesome-cordova-plugins/video-editor": "^6.0",
    "@capacitor-community/camera-preview": "^5.0.0",
    "@capacitor/android": "^5.0.0",
    "@capacitor/app": "^5.0.0",
    "@capacitor/camera": "^5.0.0",
    "@capacitor/core": "^5.0.0",
    "@capacitor/filesystem": "^5.0.0",
    "@capacitor/haptics": "^5.0.0",
    "@capacitor/ios": "^5.0.0",
    "@capacitor/keyboard": "^5.0.0",
    "@capacitor/push-notifications": "^5.0.0",
    "@capacitor/splash-screen": "^5.0.0",
    "@capacitor/status-bar": "^5.0.0",
    "@ionic/angular": "^7.3.3",
    "@ionic/angular-server": "^7.3.3",
    "@ionic/core": "^7.3.3",
    "@ionic/pwa-elements": "^3.2.2",
    "@ionic/storage-angular": "^4.0.0",
    "@ngx-translate/core": "^15.0.0",
    "@ngx-translate/http-loader": "^8.0.0",
    "@spoonconsulting/cordova-plugin-background-upload": "^4.0.10",
    "@teamhive/lottie-player": "^1.0.0",
    "capacitor-resources": "^2.0.5",
    "cordova-clipboard": "^1.3.0",
    "cordova-open-native-settings": "^1.5.5",
    "cordova-plugin-advanced-http": "^3.3.1",
    "cordova-plugin-android-permissions": "^1.1.5",
    "cordova-plugin-background-mode": "^0.7.3",
    "cordova-plugin-badge": "^0.8.9",
    "cordova-plugin-camera": "^6.0.0",
    "cordova-plugin-device": "^2.1",
    "cordova-plugin-file": "^8.0",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-filepath": "^1.6.0",
    "cordova-plugin-insomnia": "^4.3.0",
    "cordova-plugin-screen-orientation": "^3.0.3",
    "cordova-plugin-splashscreen": "^6.0.2",
    "cordova-plugin-video-editor": "^1.1.3",
    "date-fns": "^2.30.0",
    "es6-promise-plugin": "^4.2.2",
    "install": "^0.13.0",
    "luxon": "^3.4.3",
    "npm": "^10.1.0",
    "rxjs": "^7.8.1",
    "tslib": "^2.6.2",
    "zone.js": "^0.13"

My AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">

        <activity
            android:exported="true"
            android:grantUriPermissions="true"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="com.package.app.MainActivity"
            android:label="@string/title_activity_main"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/custom_url_scheme" />
            </intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
    <!-- 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.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <!-- Geolocation API -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <!-- Network API -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Navigator.getUserMedia -->
    <!-- Video -->
    <uses-permission android:name="android.permission.CAMERA" />
    <!-- Audio -->
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
     <queries>
        <package android:name="com.google.android.gm" />
        <package android:name="com.facebook.katana" />
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" />
        </intent>
        <intent>
            <action android:name="android.intent.action.DIAL" />
            <data android:scheme="tel" />
        </intent>
        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>
</manifest>

And my capacitor config

import { CapacitorConfig } from '@capacitor/cli';
import { KeyboardResize } from '@capacitor/keyboard';

const config: CapacitorConfig = {
  appId: 'com.package.app',
  appName: 'Package',
  webDir: 'www',
  bundledWebRuntime: false,
  android: {
  },
  plugins: {
    SplashScreen: {
      launchShowDuration: 2000,
      androidScaleType: "CENTER_CROP",
      launchAutoHide: true,
      androidSplashResourceName: "splash",
      androidSpinnerStyle: "large",
      iosSpinnerStyle: "small",
      spinnerColor: "#f7f4ff",
      showSpinner: false,
      splashFullScreen: true,
      splashImmersive: true
    },
    LocalNotifications: {
      smallIcon: 'ic_stat_icon_config_sample',
      iconColor: '#CE0B7C',
    },
    PushNotifications: {
      presentationOptions: ['alert', 'sound'],
    },
    Keyboard: {
      resize: KeyboardResize.Native,
      resizeOnFullScreen: true,
    },
  },
  server: {
    androidScheme: 'http',
  }
};

export default config;

Hoping you can help me

shiv19 commented 5 months ago

@rudyZanotti /__cdvfile_files-external__/files/videos/bc6e7359-db44-4629-9e91-dd8719ef7e05-1694270541591.mp4 is not a valid file path. You just want to be using the part after __cdvfile_files-external__ Something like /files/videos/bc6e7359-db44-4629-9e91-dd8719ef7e05-1694270541591.mp4 And I guess the Directory you want to use here would be Data directory.