diff --git a/app/lib/util/debug_screen.dart b/app/lib/util/debug_screen.dart index 2f6b97bee..be2021759 100644 --- a/app/lib/util/debug_screen.dart +++ b/app/lib/util/debug_screen.dart @@ -215,10 +215,13 @@ class DebugScreen { } static Future _deleteCacheDir() async { - final cacheDir = await getTemporaryDirectory(); - - if (cacheDir.existsSync()) { - cacheDir.deleteSync(recursive: true); + try { + final cacheDir = await getTemporaryDirectory(); + if (cacheDir.existsSync()) { + cacheDir.deleteSync(recursive: true); + } + } catch (e) { + StudyULogger.error(e); } } diff --git a/app/lib/util/temporary_storage_handler.dart b/app/lib/util/temporary_storage_handler.dart index b2c35017b..28c6926fc 100644 --- a/app/lib/util/temporary_storage_handler.dart +++ b/app/lib/util/temporary_storage_handler.dart @@ -22,11 +22,25 @@ class TemporaryStorageHandler { } static Future _getMultimodalTempDirectory() async { - final tempAppData = await getTemporaryDirectory(); - final multimodalTempDirectory = - Directory("${tempAppData.path}/multimodal-temp"); - await multimodalTempDirectory.create(recursive: true); - return multimodalTempDirectory; + try { + final tempAppData = await getTemporaryDirectory(); + final multimodalTempDirectory = + Directory("${tempAppData.path}/multimodal-temp"); + + if (!await multimodalTempDirectory.exists()) { + await multimodalTempDirectory.create(recursive: true); + } + + return multimodalTempDirectory; + } catch (e) { + StudyULogger.error("Failed to create multimodal temp directory: $e"); + + final fallbackDirectory = + Directory("${Directory.systemTemp.path}/multimodal-temp-fallback"); + + await fallbackDirectory.create(recursive: true); + return fallbackDirectory; + } } static Future _getMultimodalUploadDirectory() async { @@ -66,6 +80,7 @@ class TemporaryStorageHandler { Future getStagingAudio() async { final temporaryMultimodalDirectory = await _getMultimodalTempDirectory(); + final fileName = _buildFileName(); final localFilePath = path.join( temporaryMultimodalDirectory.path, @@ -75,6 +90,7 @@ class TemporaryStorageHandler { TemporaryStorageHandler._audioFileType, ].join(), ); + final futureBlobId = [fileName, TemporaryStorageHandler._audioFileType].join(); return FutureBlobFile(localFilePath, futureBlobId); @@ -91,6 +107,7 @@ class TemporaryStorageHandler { TemporaryStorageHandler._imageFileType, ].join(), ); + final futureBlobId = [fileName, TemporaryStorageHandler._imageFileType].join(); return FutureBlobFile(localFilePath, futureBlobId);