feat(capacitor): implement storage permission checks for file operations

- Add permission checks before writeFile and writeAndShareFile operations
- Reuse existing checkStoragePermissions method for Android devices
- Maintain iOS-specific handling (early return for iOS permission model)
- Improve error handling and logging for permission-related issues

This change ensures proper storage permission handling on Android devices
while maintaining the existing iOS behavior. The permission checks run
before any file write operations, providing better error handling and
user experience.
This commit is contained in:
Matthew Raymer
2025-05-28 05:56:58 +00:00
parent 8749f1d0a8
commit 2060553340

View File

@@ -358,6 +358,9 @@ export class CapacitorPlatformService implements PlatformService {
*/ */
async writeFile(fileName: string, content: string): Promise<void> { async writeFile(fileName: string, content: string): Promise<void> {
try { try {
// Check storage permissions before proceeding
await this.checkStoragePermissions();
const logData = { const logData = {
targetFileName: fileName, targetFileName: fileName,
contentLength: content.length, contentLength: content.length,
@@ -499,6 +502,9 @@ export class CapacitorPlatformService implements PlatformService {
logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2)); logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2));
try { try {
// Check storage permissions before proceeding
await this.checkStoragePermissions();
const { uri } = await Filesystem.writeFile({ const { uri } = await Filesystem.writeFile({
path: fileName, path: fileName,
data: content, data: content,