tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] FS Doesn't Work on IOS

Open Kai-Toyata opened this issue 2 years ago • 3 comments

Describe the bug

FS's readDir() (being called from JS front-end) is giving me "No such file or directory" for any path I've tried on an IOS simulator.

I have set the permissions correct, but it appears fs cannot access any files in the IOS filesystem

ERROR""failed to read directory at path: / with error: No such file or directory (os error 2)""

Is the error shown in the web console (inspected via safari).

Reproduction

Create a Tauri 2.0 app

Add { "identifier": "fs:scope", "allow": [ {"path":"$HOME/**"}, {"path":"**"}, {"path":"$HOME"} ] }, to capabilities

install fs plugin

Then call the readDir() function from JS

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.1.2 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.75.0 (82e1608df 2023-12-21)
    ✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.10.0
    - npm: 10.2.3
    - bun: 1.0.18

[-] Packages
    - tauri [RUST]: 2.0.0-beta.2
    - tauri-build [RUST]: 2.0.0-beta.1
    - wry [RUST]: 0.35.2
    - tao [RUST]: 0.25.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.0
    - @tauri-apps/cli [NPM]: 2.0.0-beta.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist/test/browser
    - devUrl: http://localhost:1420/
    - framework: Angular
    - bundler: Webpack

[-] iOS
    - Developer Teams: REDACTED

Stack trace

No response

Additional context

No response

Kai-Toyata avatar Feb 12 '24 10:02 Kai-Toyata

I'm having the same problem how can I access the file system on tauri IOS.

0PandaDEV avatar Jul 30 '24 21:07 0PandaDEV

heads up you can only access the APPCACHE directory on iOS (device, it'll work in the simulator)

I set the permission in the capabilities like this:

  "permissions": [
    "core:default",
    "shell:allow-open",
    "log:default",
    "fs:create-app-specific-dirs",
    "fs:read-app-specific-dirs-recursive",
    "fs:allow-appcache-meta",
    "fs:allow-appcache-meta-recursive",
    "fs:allow-appcache-read",
    "fs:allow-appcache-read-recursive",
    "fs:allow-appcache-write",
    "fs:allow-appcache-write-recursive",
    "store:default"
  ]

and if you need to use the asset protocol you'll need something like this in the tauri.conf.json:

"security": {
    "assetProtocol": {
      "enable": true,
      "scope": [
        "$APPCACHE/song",
        "$APPCACHE/encoded-arrangement",
        "$APPCACHE/arrangement",
        "$APPCACHE/intermix",
        "$APPCACHE/waveform",
        "$APPCACHE/song/*",
        "$APPCACHE/encoded-arrangement/*",
        "$APPCACHE/arrangement/*",
        "$APPCACHE/intermix/*",
        "$APPCACHE/waveform/*"
      ]
    }
  }
  ```

bradleat avatar Aug 23 '24 08:08 bradleat

is there any examples for iOS files and Paths? how do we get a legit path to work with files in.

AlpineVibrations avatar Oct 10 '24 18:10 AlpineVibrations

I just discovered @kennardpeters's tauri plugin for using fs on ios (https://github.com/kennardpeters/tauri-plugin-fs-ios). Will try it now but happy for anyone with more info!

do-me avatar Feb 09 '25 16:02 do-me

If this helps a bit, I am able to access files on iOS using this method (JS). Brings up file picker (Files app) and allows selection of the file type specified.

      if (isIOS) {
        // Use a different approach for iOS
        const input = document.createElement('input')
        input.type = 'file'
        // Update accept attribute to include all possible CSV MIME types and extensions
        input.accept =
          '.csv,.CSV,text/csv,application/csv,application/vnd.ms-excel'

        // Convert the file input promise to a Promise
        selected = await new Promise((resolve) => {
          /** @param {Event} e */
          input.onchange = (e) => {
            /** @type {HTMLInputElement} */
            const target = /** @type {HTMLInputElement} */ (e.target)
            const file = target.files?.[0]
            resolve(file || null)
          }
          input.click()
        })
      }

bjbk avatar Feb 09 '25 16:02 bjbk

@bjbk thanks for sharing, that might be useful for debugging. However in my case that's not quite what I want the final user experience to be like. I need to load large files in the background and perform these actions automatically.

@bradleat using Appcache also didn't work for me. Do you by chance have some minimal github test repo with a working config? That would really save us some headache I guess :D

This is my test repo in case anyone needs a working repo/config to play with: https://github.com/do-me/tauri-embedanything-ios

do-me avatar Feb 09 '25 17:02 do-me