hopefully workings uploads

This commit is contained in:
Martin Quarda 2024-10-07 07:26:08 +02:00
parent b48b24cc0e
commit 86e97dd55a

View File

@ -15,6 +15,7 @@ class Main extends Component {
constructor(props) {
super(props);
this.state = {
files: [],
text: "",
status: "",
faq: false,
@ -54,11 +55,18 @@ class Main extends Component {
onHashChange(event){
this.setState({page: window.location.hash})
}
handleChange(event) {
this.setState({files: [...event.target.files]})
}
onSubmit(event){
event.preventDefault();
let form = document.getElementById("form");
let api_endpoint = form.action;
let formData = new FormData(form);
this.state.files.forEach((file, _)=>{
formData.append(`${file.name}`, file);
})
formData
fetch(addr_prefix + api_endpoint, {
method:"POST",
body: formData,
@ -145,7 +153,7 @@ class Main extends Component {
{this.state.page == "#upload_files" &&
<div>
<form id="form" action="/api/upload_files" class="container" onSubmit={(e) => this.onSubmit(e)}>
<label>Zvolte soubory <input type="file" accept=".jpg,.png,.webp,.webm,.avi,.mkv,.mp4" multiple="true" /></label>
<label>Zvolte soubory <input type="file" accept=".jpg,.png,.webp,.webm,.avi,.mkv,.mp4" multiple="true" onChange={(e)=> this.handleChangeFiles(e)}/></label>
<button type="submit" class="btn btn-primary">Nahrát</button>
</form>
</div>}