我想将我的HTML文件输入保存到目的地,但是出了点问题。我必须在“ fs”中使用什么编码。在保存之前是否必须将其设置为二进制?或者是否具有其他编码。
const electron = require('electron');
const fs = require('fs');
const ipc = electron.ipcRenderer;
document.getElementById('fileinput').addEventListener('change', function () {
var file = this.files[0];
fs.writeFile('./src/models/steve.png', file, 'binary' ,function (err) {
ipc.send('reloadMainWindow');
});
}, false);
}
<!DOCTYPE html>
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Import Skin</title>
</head>
<body>
<p id="tmp">Please choose a skin to preview</p>
<input type="file" id="fileinput" />
<script src="" async defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
require('../scripts/saveSkin.js');
</script>
</body>
</html>