![](/img/trans.png)
[英]how open transform xml file that is in my project folder in Javascript Object
[英]Use javascript to save file in my project folder
我對 reactJS 非常陌生,我正在嘗試創建一個簡單的 Web 應用程序,它允許我上傳文件,然后將該文件保存到我的項目目錄中。
我已經嘗試過 browserify-fs,但是當我使用 fs.writeFile 時它似乎沒有創建文件
下面的代碼允許我上傳文件,但我正在努力將文件保存在我的項目目錄中
import ReactDOM from 'react-dom';
import Dropzone from 'react-dropzone';
class App extends Component {
onDrop = (acceptedFiles) => {
// Save acceptedFiles in this scripts directory
}
render() {
return (
<Dropzone onDrop={this.onDrop}>
{({getRootProps, getInputProps}) => (
<div {...getRootProps()}>
<input {...getInputProps()} />
Click me to upload a file!
</div>
)}
</Dropzone>
);
}
}
export default App;
ReactDOM.render(
<App />,
document.getElementById('root')
);
browserify-fs
將數據存儲在瀏覽器中(我假設使用本地存儲,但我找不到明確的說明)。
如果要將數據存儲在服務器上,則需要:
使用以下函數...
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
...並按如下方式調用...
download('Text to Save to the File', 'TestSave.txt', 'text/plain')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.