File
Object对象
Use the HTML5使用HTML5 FILE API以本机方式处理文件系统上的文件。File
API to work natively with files on the filesystem.
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. DOM的File接口提供了对本机文件的抽象,以便用户可以直接使用HTML5文件API处理本机文件。Electron has added a Electron为path
attribute to the File
interface which exposes the file's real path on filesystem.File
接口添加了一个path
属性,该属性公开了文件在文件系统上的真实路径。
Example of getting a real path from a dragged-onto-the-app file:从拖动到应用程序文件中获取真实路径的示例:
<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>