diff --git a/packages/jsActions/mobile-resources-native/CHANGELOG.md b/packages/jsActions/mobile-resources-native/CHANGELOG.md index c80d2393c..b9746fcf0 100644 --- a/packages/jsActions/mobile-resources-native/CHANGELOG.md +++ b/packages/jsActions/mobile-resources-native/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - The Play sound action now plays audio files from online (network) documents on Android by downloading them to a version-based cache before playback. - We have fixed the biometric authentication issue where it was not working on Android and crashing on iOS. - Fixed an issue where the `TakePicture` and `TakePictureAdvanced` actions failed to capture photos on Android. +- Fixed an issue where the `TakePicture` and `TakePictureAdvanced` actions did not properly clean up temporary files. ## [12.1.0] Native Mobile Resources - 2026-6-10 diff --git a/packages/jsActions/mobile-resources-native/src/camera/TakePicture.ts b/packages/jsActions/mobile-resources-native/src/camera/TakePicture.ts index 69790ba27..f80254be5 100644 --- a/packages/jsActions/mobile-resources-native/src/camera/TakePicture.ts +++ b/packages/jsActions/mobile-resources-native/src/camera/TakePicture.ts @@ -116,6 +116,15 @@ export async function TakePicture( }); } + async function safeRemove(filePath: string): Promise { + try { + await NativeModules.MxFileSystem.remove(filePath); + } catch (error) { + console.warn(`Failed to remove file at ${filePath}. Error: ${error}`); + // ignore error + } + } + function storeFile(imageObject: mendix.lib.MxObject, uri: string): Promise { return new Promise((resolve, reject) => { NativeModules.MxFileSystem.read(uri.replace("file://", "")) @@ -138,7 +147,7 @@ export async function TakePicture( {}, blob, async () => { - await NativeModules.MendixNative.fsRemove(filePathWithoutFileScheme); + await safeRemove(filePathWithoutFileScheme); imageObject.set("Name", filename); @@ -149,7 +158,7 @@ export async function TakePicture( }); }, async (error: Error) => { - await NativeModules.MendixNative.fsRemove(filePathWithoutFileScheme); + await safeRemove(filePathWithoutFileScheme); reject(error); } diff --git a/packages/jsActions/mobile-resources-native/src/camera/TakePictureAdvanced.ts b/packages/jsActions/mobile-resources-native/src/camera/TakePictureAdvanced.ts index 562502f99..d283dab5f 100644 --- a/packages/jsActions/mobile-resources-native/src/camera/TakePictureAdvanced.ts +++ b/packages/jsActions/mobile-resources-native/src/camera/TakePictureAdvanced.ts @@ -169,6 +169,15 @@ export async function TakePictureAdvanced( }); } + async function safeRemove(filePath: string): Promise { + try { + await NativeModules.MxFileSystem.remove(filePath); + } catch (error) { + console.warn(`Failed to remove file at ${filePath}. Error: ${error}`); + // ignore error + } + } + function storeFile(imageObject: mendix.lib.MxObject, uri: string): Promise { return new Promise((resolve, reject) => { NativeModules.MxFileSystem.read(uri.replace("file://", "")) @@ -191,7 +200,7 @@ export async function TakePictureAdvanced( {}, blob, async () => { - await NativeModules.MendixNative.fsRemove(filePathWithoutFileScheme); + await safeRemove(filePathWithoutFileScheme); imageObject.set("Name", filename); @@ -202,7 +211,7 @@ export async function TakePictureAdvanced( }); }, async (error: Error) => { - await NativeModules.MendixNative.fsRemove(filePathWithoutFileScheme); + await safeRemove(filePathWithoutFileScheme); reject(error); }