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