EinfachHans/cordova-plugin-advanced-imagepicker

Android Image File Not Recognised As Image

Mr-Anonymous opened this issue · 0 comments

Bug Report

Current Behavior:

When some Android devices uploads the selected images, my server does not recognise that this is an image. At first I thought it was maybe due to the plugin result returning the src as a content url like "content://media/external/images/media/1000036553", but I don't think that is the case. Because when I tested the same from my Android 13 device, the same content src gets uploaded just fine. Has anyone else found this issue?

Expected Behavior:
The file should be recognised as an image.

Steps to reproduce:

This is the code I have:

Image picker selects the images:

window.AdvancedImagePicker.present({
              // config here
                max: (limit > 1) ? 30 : 1,
                maxCountMessage: 'Only 30 images can be uploaded at a time'
            }, function(success) {
              console.log(success);
              var results = success;
              // The file is then transferred via FileTransfer plugin
            }, function (error) {
              // console.error(error);
            });

My server does a validation check like:

$rules = array(
           'image' => 'mimes:'. 'jpeg,jpg,png,gif' .'|required
       );

The error is thrown here is:

Device: android, 
OS: android 13, 
Error: {
"code":"1",
"source":"content:\/\/media\/external\/images\/media\/1000059240",
"target":"my-upload-url",
"http_status":"400",
"body":"{\"imageError\":{\"image\":[\"The image must be a file of type: jpeg, jpg, png, gif.\"]}}"}

The 2 Android devices that I have, I could not replicate the issue. But a lot of users who are using Android 12 and 13 are having these errors and my error logs are filled with many like this. So it seems the same code works for some and for others the image is not recognised. Why is that does anyone know please?

Environment information:

Ionic:

   Ionic CLI         : 6.18.1 (/Users/me/.nvm/versions/node/v18.18.2/lib/node_modules/@ionic/cli)
   Ionic Framework   : ionic1 1.3.3
   @ionic/v1-toolkit : 1.0.9

Cordova:

   Cordova CLI       : 12.0.0 (cordova-lib@12.0.1)
   Cordova Platforms : android 12.0.0, ios 6.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, (and 17 other plugins)

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   Android SDK Tools : 26.1.1 (/Users/me/Library/Android/sdk)
   ios-sim           : 8.0.2
   NodeJS            : v18.18.2 (/Users/me/.nvm/versions/node/v18.18.2/bin/node)
   npm               : 6.14.7
   OS                : macOS Monterey
   Xcode             : Xcode 14.2 Build version 14C18