From 198be75e9adcc1fd6c2c6eb6b55a2f828a2a3504 Mon Sep 17 00:00:00 2001 From: shen Date: Thu, 30 Oct 2025 21:51:40 +0800 Subject: [PATCH] fix(web): Check the existence of the folder before mkdir. --- packages/capacitor-plugin/src/web.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/capacitor-plugin/src/web.ts b/packages/capacitor-plugin/src/web.ts index 1962d2f..fdc3ea6 100644 --- a/packages/capacitor-plugin/src/web.ts +++ b/packages/capacitor-plugin/src/web.ts @@ -12,6 +12,7 @@ import type { // Type definitions for the Capacitor Filesystem API interface FilesystemPlugin { readFile(options: { path: string }): Promise<{ data: string }>; + stat(options: { path: string }): Promise<{ data: string }>; writeFile(options: { path: string; data: string; @@ -469,9 +470,11 @@ export class FileTransferWeb extends WebPlugin implements FileTransferPlugin { const pathParts = path.split("/"); if (pathParts.length > 1) { const directory = pathParts.slice(0, -1).join("/"); - await filesystem.mkdir({ - path: directory, - recursive: true, + await filesystem.stat({path: directory}).catch(async ()=>{ + await filesystem.mkdir({ + path: directory, + recursive: true, + }); }); }