try {
// Fetch the file as a Blob
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
//console.log("downloadFileAsync:ASYNC response OK for:" + filename + ext);
const blob = await response.blob();
// Create a temporary URL for the Blob
//const fileURL = URL.createObjectURL(blob)
const _type = getTypeByEXT(ext);
const fileURL = URL.createObjectURL(new Blob([blob], { type: _type }));
// Create a link element to trigger the download
const link = document.createElement('a');
link.href = fileURL;
link.download = filename + ext; // Suggests a filename for the download
link.style.display = 'none'; // Hide the link
// Programmatically click the link to initiate download
document.body.appendChild(link);
link.click();
// Remove the link from the body
document.body.removeChild(link); // Clean up the link element
// Revoke the object URL to free up memory
URL.revokeObjectURL(fileURL);
console.log(`${filename}${ext} downloaded successfully.`);
} catch (error) {
console.error(`Error downloading ${filename}${ext}:`, error);
}
}
< /code>
строка 14 из фрагмента выше: < /strong> < /p>
- const fileUrl = url.createObjecturl < /strong> (blob);
и < /li>
const fileurl = url Blob ([[strong> blob ], {type: ext }));
изображения никогда не загружают. Blob (...) < /p>
Я использовал 1) < /strong> во -первых, всегда работал для видео, но не < /strong>. Итак, я получаю загрузки.
setTimeout(() => {
// Recursively call the function with the rest of the array (excluding the first element)
processDownloadArrayWithDelay(arr.slice(1), delay);
}, delay);
< /code>
, а также с < /p>
downloadFileAsync(url, fn, ext);
< /code>
Причина, по которой я использую рекурсию и settimeout, заключается в том, что обещания не работали. обещает осталось невыполненным. Как я уже сказал, видео загружают хорошо, изображения никогда ...
Подробнее здесь: https://stackoverflow.com/questions/796 ... eos-fine-i
Мобильная версия