improve image download with blob conversion for cross-origin support

This commit is contained in:
jingrow 2025-11-21 02:03:24 +08:00
parent 435c4740b9
commit 67a117f65f

View File

@ -487,17 +487,29 @@ const handleDownload = async () => {
if (!resultImage.value) return
try {
// Blob
const response = await fetch(resultImage.value)
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const blob = await response.blob()
const blobUrl = URL.createObjectURL(blob)
//
const link = document.createElement('a')
link.href = resultImage.value
link.href = blobUrl
link.download = `removed-background-${Date.now()}.png`
link.target = '_blank'
link.style.display = 'none'
document.body.appendChild(link)
link.click()
setTimeout(() => {
// DOM blob URL
requestAnimationFrame(() => {
document.body.removeChild(link)
}, 100)
URL.revokeObjectURL(blobUrl)
})
message.success(t('Download started'))
} catch (error: any) {