#forbidden path: ... How to create file with fs plugin?

4 messages · Page 1 of 1 (latest)

jolly depot
#

Hi, can you give me simple example of how to create file on android and desktop(mac)?

I installed fs plugin.
For Android i've added permissions to manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...

Also i've edited capabilities/default.json:

"permissions": [
    "core:default",
    "opener:default",
    "fs:default",
    "fs:allow-create", // added

I try to create file within my react component:

useEffect(() => {
    async function createFile() {
      try {
        const file = await create("foobar.txt", {
          baseDir: BaseDirectory.AppData,
        });

        setState("FileCreated");
        console.debug("File created successfully!");
      } catch (error) {
        setState(error);
      }
    }

    createFile();
  }, []);

And got Error:
On tauri android dev : forbidden path: /data/user/0/com.bank_note.app/foobar.txt

On tauri dev: forbidden path: /Users/philipp/Library/Application Support/com.bank-note.app/foobar.txt

What did i do wrong?

jolly depot
#

Ok, seems like i fixed this by adding: "fs:allow-appdata-write" what is interesting, that "fs:allow-write" not working.

Also i need to add "fs:allow-exists" for desktop, BUT i got error: Failed to create file at path: /Users/philipp/Library/Application Support/com.bank-note.app/foobar.txt with error: No such file or directory (os error 2)
I think this is because when i run tauri dev it does not create com.bank-note.app. What is the correct way of dealing with this in dev?? Should i manually create folder or any tauri tool can help with this?

nimble hill
#

i think, you have to add the "allow path" too

{
  "identifier": "fs:allow-exists",
  "allow": [ { "path": "$APPDATA/*" }]
}
jolly depot