#How to load a local Image from the file system

19 messages · Page 1 of 1 (latest)

steel thunder
#

<script lang="ts">
    import { convertFileSrc } from '@tauri-apps/api/tauri';
    export let images: string[] = [];
    
</script>
<div class="grid">
     {#each images as image}
     <div class="container">
         <img src={convertFileSrc(image)} alt="bild"/>
     </div>
     {/each}
</div>```
config:
```json
 "fs": {
        "all": true,
        "copyFile": false,
        "createDir": false,
        "exists": true,
        "readDir": true,
        "readFile": true,
        "removeDir": false,
        "removeFile": false,
        "renameFile": false,
        "scope": [],
        "writeFile": false
      }```
Thats what i tried, but it doesnt work
tough fractal
#

you need add it into scope

steel thunder
#

what do you mean by that?

tough fractal
#

add paths that you need load into scope

#

and if you are not empty the images array by some reason, then need also add into that images array

void cedar
#

I've got a previous (currently not functional, so I can't test anything there atm) PoC project where I accessed files. I had this as my security setting in tauri.conf.json:

"security": {
  "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost"
},
#

I also had allowlist configured like this:

"allowlist": {
  [...]
  "protocol": {
    "asset": true,
    "assetScope": ["*"]
  }
},
#

a big todo was to check if I could further limit any of those, and figure out what that csp property actually means, cause this is very permissive. Like I said, it was a proof of concept, so I was more concerned with getting it working than getting it working properly. Referring to local files anywhere on the user's system is also kinda the point of the application I'm building

steel thunder
#

That worked when i put the file path in the config. But i cant get a config to work wich allows all files

#

"*" this pattern does not work

sullen smelt
#

maybe try "**"

#

and of course these kind off allow-all patterns are obviously discouraged, and actually not that often necessary. But it's alright for PoC purposes of course

steel thunder
#

thx that worked

#

i dont think i can use something else, since the program should access different directories which the user chosses

sullen smelt
#

which the user chosses
If you use tauri's file/folder dialog, the selected paths will get added to the scope automatically

#

and you could extend the scope in rust at runtime if using a bit of rust is acceptable

steel thunder
#

yes, rust is planed and used

steel thunder
#

could you point me to the rust function?