tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] BaseDirectory.Temp leads to wrong folder

Open raphaelsiz opened this issue 7 months ago • 1 comments

Describe the bug

I'm making an app that needs to save HTML5 canvas data to be able to use it in a command passed to the computer. The first thing I need to do is save the canvas data as an image, and then I ask the Rust backend to verify the path before using it in the command. Here's my current JavaScript code to save the images:

async function generateGuides() {
    let frame = frames[current]
    let num = frame.frameStr
    for (let layer of layers) {
        try {
            let binary = atob(frame[layer].toDataURL().replace(/^data:image\/\w+;base64,/,''))
            let binaryArray = new Uint8Array(binary.length)
            for (let i = 0; i < binary.length; i++) {
                binaryArray[i] = binary.charCodeAt(i)
            }
            let path = `${layer}${num}.png`
            await writeBinaryFile(path,binaryArray,{baseDir:BaseDirectory.Temp})
        } catch (e) {
            console.error(e)
        }
    }
    let paths = await invoke("get_layers",{frame:current,names:layers})
    return paths
}

Everything is working fine except that the image is saving to the wrong place. According to the Rust backend (env::temp_dir()), my temp folder is '/tmp' (makes sense). But no files are being saved to that directory. When I run the development build, the images are being saved to my 'src-tauri' folder of the project.

src-tauri folder in VSCodium, showing several images that are highlighted in green because they haven't been added to the git repo

When I run a production build, I have no idea where the images are being saved to and no confirmation that they're actually being saved--but considering they're being saved just fine by the dev build, it seems likely that I just don't know where they are.

Reproduction

  1. Create Tauri project on a Linux system (Debian 12 in my case)
  2. Use the v1 JavaScript API to save a file with await writeBinaryFile(path,binaryArray,{baseDir:BaseDirectory.Temp})
  3. Observe where the file was saved

Expected behavior

I expected the file to be saved either to my '/tmp' folder or another specific directory intended for temp files, and for it to be saved to the same folder regardless of whether I'm running a development build or a production build.

Full tauri info output

[✔] Environment
    - OS: Debian 12.0.0 X64
    ✔ webkit2gtk-4.0: 2.44.2
    ✔ rsvg2: 2.54.7
    ✔ rustc: 1.79.0 (129f3b996 2024-06-10)
    ✔ cargo: 1.79.0 (ffa9cf99a 2024-06-03)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)
    - node: 20.14.0
    - npm: 10.8.1

[-] Packages
    - tauri [RUST]: 1.7.1
    - tauri-build [RUST]: 1.5.3
    - wry [RUST]: 0.24.10
    - tao [RUST]: 0.16.9
    - tauri-cli [RUST]: 1.5.14
    - @tauri-apps/api [NPM]: 1.6.0
    - @tauri-apps/cli [NPM]: 1.6.0

[-] App
    - build-type: bundle
    - CSP: default-src 'self'; img-src 'self' asset: https://asset.localhost
    - distDir: ../build
    - devPath: http://localhost:5173/
    - framework: Svelte
    - bundler: Vite

Stack trace

No response

Additional context

No response

raphaelsiz avatar Jul 13 '24 06:07 raphaelsiz