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