electron/docs-translations/zh-CN/api/file-object.md
2017-01-22 14:17:59 +08:00

30 lines
805 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# `File` 对象
> 在文件系统上使用 HTML5 `File` API 与本地文件交互。
为了让用户能够通过 HTML5 的 file API 直接操作本地文件DOM 的 File 接口提供了对本地文件的抽象。Electron 在 File 接口中增加了一个 path 属性,它是文件在系统中的真实路径。
获取拖动到 APP 中文件的真实路径的例子:
```html
<div id="holder">
Drag your file here
</div>
<script>
const holder = document.getElementById('holder')
holder.ondragover = () => {
return false;
}
holder.ondragleave = holder.ondragend = () => {
return false;
}
holder.ondrop = (e) => {
e.preventDefault()
for (let f of e.dataTransfer.files) {
console.log('File(s) you dragged here: ', f.path)
}
return false;
}
</script>
```