Tauri V2创建目录报错:forbidden path: images 求助
报错‘forbidden path: images’:TypeScript中无法在Tauri应用创建目录
我正尝试在TypeScript中创建目录,但始终报错‘forbidden path: images’,无法定位问题所在。以下是相关代码与配置:
TypeScript代码
const imagesDir = `images`; const deckDir = deckName; const filePath = `${imagesDir}/${fileName}`; // Check and create directory if not exists const dirExists = await fs.exists(imagesDir); if (!dirExists) { await fs.mkdir(imagesDir, { baseDir: fs.BaseDirectory.AppData }); }
migrated.json权限配置
{ "identifier": "migrated", "description": "permissions that were migrated from v1", "local": true, "windows": [ "main" ], "permissions": [ "core:default", "shell:allow-open", "fs:default", "fs:allow-open", "fs:allow-write", "fs:allow-read", "fs:allow-rename", "fs:allow-mkdir", "fs:allow-remove", "fs:allow-write-text-file", "fs:scope-download-recursive", "fs:scope-resource-recursive", { "identifier": "fs:scope", "allow": [{ "path": "$APPDATA" }, {"path": "$APPDATA/*" }] }, "shell:default", "dialog:default" ] }
Rust代码
tauri::Builder::default() .setup(|app| { let path = app.path().app_data_dir().expect("This should never be None"); let path = path.join("images/"); create_dir_all(&path)?; Ok(()) }) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_fs::init()) .invoke_handler(tauri::generate_handler![ /*REDACTED*/ ]) .on_window_event(|window, event| { if let WindowEvent::CloseRequested { .. } = event { // Perform the save action here if let Err(e) = save_to_disk() { eprintln!("Failed to save data to disk: {}", e); } } }) .run(tauri::generate_context!()) .expect("error while running tauri application");
我曾将JSON配置中的路径改为“$APPDATA/**”,Rust中的路径改为“/.images”,也调整过权限、路径及基础目录,期望应用能创建目录并保存文件,但报错始终存在,恳请各位提供帮助。
内容的提问来源于stack exchange,提问作者Sora Hirasawa
相关产品推荐
相关产品推荐

