Näytä tarkka virheviesti uploadissa

This commit is contained in:
2026-03-08 01:15:51 +02:00
parent 9236aee4a2
commit a1a7a2167f
2 changed files with 10 additions and 6 deletions

View File

@@ -491,20 +491,22 @@
const lbl = document.getElementById(labelId);
lbl.style.opacity = '0.5';
const resized = await resizeImage(file);
let resized;
try { resized = await resizeImage(file); } catch (e) { lbl.style.opacity = ''; showToast('⚠️ Kuvan käsittely epäonnistui: ' + e.message); return; }
const formData = new FormData();
formData.append('file', resized, resized.name || 'image.jpg');
try {
const res = await fetch('upload.php', { method: 'POST', body: formData });
if (!res.ok) throw new Error(await res.text());
const data = await res.json();
if (data.error) throw new Error(data.error);
document.getElementById(hiddenId).value = data.url;
const prev = document.getElementById(previewId);
prev.src = data.url;
prev.style.display = 'block';
lbl.classList.add('has-image');
} catch (e) {
showToast('⚠️ Kuvan lataus epäonnistui. Tuetut muodot: JPG, PNG, GIF, WebP (max 20 MB).');
showToast('⚠️ ' + e.message);
} finally {
lbl.style.opacity = '';
}