Skip to content

Commit 6edbb12

Browse files
chore: update ref to docs (🤖) (#879)
Co-authored-by: electron-website-docs-updater[bot] <166660481+electron-website-docs-updater[bot]@users.noreply.github.com>
1 parent 1e62a88 commit 6edbb12

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎docs/latest/.sha‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
074d0e19fbe22e64a41ba6d1d390033a204687d2
1+
347fd37dfbf089f2d66aebd0811672d93f49bb6f

‎docs/latest/api/web-utils.md‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,27 @@ Returns `string` - The file system path that this `File` object points to. In th
2424
This 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
```

0 commit comments

Comments
 (0)