electron/docs-translations/zh-CN/api/file-object.md

34 lines
1 KiB
Markdown
Raw Normal View History

2016-02-17 02:42:59 +00:00
# `文件`对象
为了让用户能够通过HTML5的file API直接操作本地文件DOM的File接口提供了对本地文件的抽象。Electron在File接口中增加了一个path属性它是文件在系统中的真实路径。
The DOMs 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 files real path on filesystem.
---
获取拖动到APP中文件的真实路径的例子
Example on getting a real path from a dragged-onto-the-app file:
```
<div id="holder">
Drag your file here
</div>
<script>
var holder = document.getElementById('holder');
holder.ondragover = function () {
return false;
};
holder.ondragleave = holder.ondragend = function () {
return false;
};
holder.ondrop = function (e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
console.log('File you dragged here is', file.path);
return false;
};
</script>
```