✨ upload image one by one
This commit is contained in:
parent
e8ed31d335
commit
b71b8c1b23
@ -824,7 +824,7 @@
|
||||
updateDataStats();
|
||||
}
|
||||
|
||||
// 批量上传图片(调用批量API以利用多卡并行)
|
||||
// 批量上传图片(串行:并发=1,每次上传一张,调用 /api/add_image)
|
||||
async function uploadBatchImages(files) {
|
||||
try {
|
||||
const progressDiv = document.getElementById('imageUploadProgress');
|
||||
@ -833,26 +833,34 @@ async function uploadBatchImages(files) {
|
||||
|
||||
progressDiv.style.display = 'block';
|
||||
progressText.textContent = `0/${files.length}`;
|
||||
progressBar.style.width = '10%';
|
||||
progressBar.style.width = '0%';
|
||||
|
||||
showAlert('info', `正在批量上传 ${files.length} 张图片...`);
|
||||
showAlert('info', `开始上传 ${files.length} 张图片(串行)...`);
|
||||
|
||||
const formData = new FormData();
|
||||
let successCount = 0;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
formData.append('images', files[i]);
|
||||
const formData = new FormData();
|
||||
formData.append('image', files[i]);
|
||||
|
||||
try {
|
||||
const resp = await fetch('/api/add_image', { method: 'POST', body: formData });
|
||||
const data = await resp.json();
|
||||
if (data && data.success) {
|
||||
successCount++;
|
||||
} else {
|
||||
// 不中断流程,记录失败
|
||||
console.warn('Upload failed for file:', files[i].name, data?.error);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Request failed for file:', files[i].name, e);
|
||||
}
|
||||
|
||||
const progress = Math.round(((i + 1) / files.length) * 100);
|
||||
progressBar.style.width = `${progress}%`;
|
||||
progressText.textContent = `${i + 1}/${files.length}`;
|
||||
}
|
||||
|
||||
const response = await fetch('/api/add_images_batch', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!data.success) {
|
||||
throw new Error(data.error || '批量上传失败');
|
||||
}
|
||||
progressBar.style.width = '100%';
|
||||
progressText.textContent = `${files.length}/${files.length}`;
|
||||
showAlert('success', data.message || `成功上传 ${files.length} 张图片`);
|
||||
showAlert('success', `上传完成:成功 ${successCount}/${files.length} 张`);
|
||||
await autoSaveIndex();
|
||||
updateDataStats();
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user