fix: return content uris when possible when selecting from gallery (#902)

This commit is contained in:
Norman Breau 2024-10-26 00:58:24 -03:00 committed by GitHub
parent a672c31efb
commit 2eaa9a3972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -728,20 +728,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
} }
} }
String fileLocation = FileHelper.getRealPath(uri, this.cordova);
LOG.d(LOG_TAG, "File location is: " + fileLocation);
String uriString = uri.toString(); String uriString = uri.toString();
String finalLocation = fileLocation != null ? fileLocation : uriString;
String mimeTypeOfGalleryFile = FileHelper.getMimeType(uriString, this.cordova); String mimeTypeOfGalleryFile = FileHelper.getMimeType(uriString, this.cordova);
if (finalLocation == null) {
this.failPicture("Error retrieving result.");
} else {
// If you ask for video or the selected file cannot be processed // If you ask for video or the selected file cannot be processed
// there will be no attempt to resize any returned data. // there will be no attempt to resize any returned data.
if (this.mediaType == VIDEO || !isImageMimeTypeProcessable(mimeTypeOfGalleryFile)) { if (this.mediaType == VIDEO || !isImageMimeTypeProcessable(mimeTypeOfGalleryFile)) {
this.callbackContext.success(finalLocation); this.callbackContext.success(uriString);
} else { } else {
// This is a special case to just return the path as no scaling, // This is a special case to just return the path as no scaling,
@ -750,7 +743,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
destType == FILE_URI && !this.correctOrientation && destType == FILE_URI && !this.correctOrientation &&
getMimetypeForEncodingType().equalsIgnoreCase(mimeTypeOfGalleryFile)) getMimetypeForEncodingType().equalsIgnoreCase(mimeTypeOfGalleryFile))
{ {
this.callbackContext.success(finalLocation); this.callbackContext.success(uriString);
} else { } else {
Bitmap bitmap = null; Bitmap bitmap = null;
try { try {
@ -787,7 +780,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.failPicture("Error retrieving image: "+e.getLocalizedMessage()); this.failPicture("Error retrieving image: "+e.getLocalizedMessage());
} }
} else { } else {
this.callbackContext.success(finalLocation); this.callbackContext.success(uriString);
} }
} }
if (bitmap != null) { if (bitmap != null) {
@ -799,8 +792,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
} }
} }
}
/** /**
* JPEG, PNG and HEIC mime types (images) can be scaled, decreased in quantity, corrected by orientation. * JPEG, PNG and HEIC mime types (images) can be scaled, decreased in quantity, corrected by orientation.
* But f.e. an image/gif cannot be scaled, but is can be selected through the PHOTOLIBRARY. * But f.e. an image/gif cannot be scaled, but is can be selected through the PHOTOLIBRARY.