working files?

This commit is contained in:
Martin Quarda 2024-10-07 10:51:51 +02:00
parent 50bc8a2034
commit b0b5449ddb
2 changed files with 3 additions and 8 deletions

View File

@ -203,7 +203,7 @@ def upload_files(request):
rand = random.randint(9999999999999)
random_name = f'photos/uploads/{rand}.jpg'
with open(random_name, "wb+") as destination:
for chunk in f.chunks():
for chunk in file.chunks():
destination.write(chunk)
return HttpResponse('{"success":"Úspěšně nahráno! Počkejte až dojde ke schválení nahraných souborů."}', content_type='application/json')

View File

@ -63,11 +63,6 @@ class Main extends Component {
let form = document.getElementById("form");
let api_endpoint = form.action;
let formData = new FormData(form);
if (this.state.files && api_endpoint == "/api/upload_files"){
this.state.files.forEach((file, _)=>{
formData.append(file.name, file);
})
}
fetch(addr_prefix + api_endpoint, {
method:"POST",
body: formData,
@ -151,10 +146,10 @@ class Main extends Component {
<div class="absolute container-fluid alert alert-danger">
{this.state.text}
</div>}
{this.state.page == "#upload_files" &&
{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" name="files" accept=".jpg,.png,.webp,.webm,.avi,.mkv,.mp4" multiple="true" onChange={(e)=> this.handleChangeFiles.bind(this)(e)}/></label>
<label>Zvolte soubory <input type="file" name="files" accept=".jpg,.png,.webp,.webm,.avi,.mkv,.mp4" multiple={true} onChange={(e)=> this.handleChangeFiles.bind(this)(e)}/></label>
<button type="submit" class="btn btn-primary">Nahrát</button>
</form>
</div>}