File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 074d0e19fbe22e64a41ba6d1d390033a204687d2
1+ 347fd37dfbf089f2d66aebd0811672d93f49bb6f
Original file line number Diff line number Diff line change @@ -24,11 +24,27 @@ Returns `string` - The file system path that this `File` object points to. In th
2424This method superseded the previous augmentation to the ` File ` object with the ` path ` property. An example is included below.
2525
2626``` js @ts-nocheck
27- // Before
28- const oldPath = document .querySelector (' input' ).files [0 ].path
27+ // Before (renderer)
28+ const oldPath = document .querySelector (' input[type=file]' ).files [0 ].path
29+ ```
2930
31+ ``` js @ts-nocheck
3032// After
31- const { webUtils } = require (' electron' )
3233
33- const newPath = webUtils .getPathForFile (document .querySelector (' input' ).files [0 ])
34+ // Renderer:
35+
36+ const file = document .querySelector (' input[type=file]' ).files [0 ]
37+ electronApi .doSomethingWithFile (file)
38+
39+ // Preload script:
40+
41+ const { contextBridge , webUtils } = require (' electron' )
42+
43+ contextBridge .exposeInMainWorld (' electronApi' , {
44+ doSomethingWithFile (file ) {
45+ const path = webUtils .getPathForFile (file)
46+ // Do something with the path, e.g., send it over IPC to the main process.
47+ // It's best not to expose the full file path to the web content if possible.
48+ }
49+ })
3450```
You can’t perform that action at this time.
0 commit comments