2016-05-20 10:25:10 -06:00
|
|
|
# `File` Object
|
2014-10-25 00:58:32 -06:00
|
|
|
|
2016-04-21 16:39:12 -06:00
|
|
|
> Use the HTML5 `File` API to work natively with files on the filesystem.
|
2016-04-21 16:35:29 -06:00
|
|
|
|
2015-08-26 17:41:25 -06:00
|
|
|
The DOM's File interface provides abstraction around native files in order to
|
2015-08-25 06:48:24 -06:00
|
|
|
let users work on native files directly with the HTML5 file API. Electron has
|
2015-08-26 17:41:25 -06:00
|
|
|
added a `path` attribute to the `File` interface which exposes the file's real
|
|
|
|
path on filesystem.
|
2014-10-25 00:58:32 -06:00
|
|
|
|
2016-11-03 11:26:00 -06:00
|
|
|
Example of getting a real path from a dragged-onto-the-app file:
|
2014-10-25 00:58:32 -06:00
|
|
|
|
|
|
|
```html
|
|
|
|
<div id="holder">
|
|
|
|
Drag your file here
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
2016-07-25 19:39:25 -06:00
|
|
|
const holder = document.getElementById('holder')
|
2016-05-04 11:59:02 -06:00
|
|
|
holder.ondragover = () => {
|
2014-10-25 00:58:32 -06:00
|
|
|
return false;
|
2016-07-25 19:39:25 -06:00
|
|
|
}
|
2016-05-04 11:59:02 -06:00
|
|
|
holder.ondragleave = holder.ondragend = () => {
|
2014-10-25 00:58:32 -06:00
|
|
|
return false;
|
2016-07-25 19:39:25 -06:00
|
|
|
}
|
2016-05-04 11:59:02 -06:00
|
|
|
holder.ondrop = (e) => {
|
2016-07-25 19:39:25 -06:00
|
|
|
e.preventDefault()
|
2016-07-19 22:51:58 -06:00
|
|
|
for (let f of e.dataTransfer.files) {
|
2016-07-25 19:39:25 -06:00
|
|
|
console.log('File(s) you dragged here: ', f.path)
|
2016-07-19 22:51:58 -06:00
|
|
|
}
|
2014-10-25 00:58:32 -06:00
|
|
|
return false;
|
2016-07-25 19:39:25 -06:00
|
|
|
}
|
2014-10-25 00:58:32 -06:00
|
|
|
</script>
|
|
|
|
```
|