feat: remove File.path (#42053)

This commit is contained in:
Jeremy Rose 2024-05-15 11:07:23 -07:00 committed by GitHub
parent a54afabe04
commit 19dc276878
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 99 deletions

View file

@ -98,7 +98,6 @@ These individual tutorials expand on topics discussed in the guide above.
### Custom DOM Elements:
* [`File` Object](api/file-object.md)
* [`<webview>` Tag](api/webview-tag.md)
* [`window.open` Function](api/window-open.md)

View file

@ -1,36 +0,0 @@
# `File` Object
> Use the HTML5 `File` API to work natively with files on the filesystem.
> **Warning**
> The `path` property that Electron adds to the `File` interface is deprecated
> and **will** be removed in a future Electron release. We recommend you
> use `webUtils.getPathForFile` instead.
The DOM's File interface provides abstraction around native files in order to
let users work on native files directly with the HTML5 file API. Electron has
added a `path` attribute to the `File` interface which exposes the file's real
path on filesystem.
Example of getting a real path from a dragged-onto-the-app file:
```html
<div id="holder">
Drag your file here
</div>
<script>
document.addEventListener('drop', (e) => {
e.preventDefault();
e.stopPropagation();
for (const f of e.dataTransfer.files) {
console.log('File(s) you dragged here: ', f.path)
}
});
document.addEventListener('dragover', (e) => {
e.preventDefault();
e.stopPropagation();
});
</script>
```

View file

@ -12,6 +12,38 @@ This document uses the following convention to categorize breaking changes:
* **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release.
* **Removed:** An API or feature was removed, and is no longer supported by Electron.
## Planned Breaking API Changes (32.0)
### Removed: `File.path`
The nonstandard `path` property of the Web `File` object was added in an early version of Electron as a convenience method for working with native files when doing everything in the renderer was more common. However, it represents a deviation from the standard and poses a minor security risk as well, so beginning in Electron 32.0 it has been removed in favor of the [`webUtils.getPathForFile`](api/web-utils.md#webutilsgetpathforfilefile) method.
```js
// Before (renderer)
const file = document.querySelector('input[type=file]')
alert(`Uploaded file path was: ${file.path}`)
```
```js
// After (renderer)
const file = document.querySelector('input[type=file]')
electron.showFilePath(file)
// (preload)
const { contextBridge, webUtils } = require('electron')
contextBridge.exposeInMainWorld('electron', {
showFilePath (file) {
// It's best not to expose the full file path to the web content if
// possible.
const path = webUtils.getPathForFile(file)
alert(`Uploaded file path was: ${path}`)
}
})
```
## Planned Breaking API Changes (31.0)
### Removed: `WebSQL` support