fix: Utiliser fetch + blob pour forcer le téléchargement des fichiers .txt
This commit is contained in:
parent
f26b41c525
commit
30d77bf7b0
1 changed files with 17 additions and 8 deletions
|
|
@ -458,7 +458,7 @@ function SectionComptables() {
|
|||
})
|
||||
}
|
||||
|
||||
const handleDownload = (item: DocumentItem, period: string) => {
|
||||
const handleDownload = async (item: DocumentItem, period: string) => {
|
||||
// Chercher l'URL dans les données chargées
|
||||
const docsWithUrls = periodUrls[period]
|
||||
if (docsWithUrls) {
|
||||
|
|
@ -468,13 +468,22 @@ function SectionComptables() {
|
|||
const isTxtFile = item.title.toLowerCase().endsWith('.txt')
|
||||
|
||||
if (isTxtFile) {
|
||||
// Forcer le téléchargement pour les fichiers .txt
|
||||
const link = document.createElement('a')
|
||||
link.href = docWithUrl.url
|
||||
link.download = item.title
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
// Forcer le téléchargement pour les fichiers .txt en utilisant fetch
|
||||
try {
|
||||
const response = await fetch(docWithUrl.url)
|
||||
const blob = await response.blob()
|
||||
const blobUrl = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = blobUrl
|
||||
link.download = item.title
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
window.URL.revokeObjectURL(blobUrl)
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du téléchargement:', error)
|
||||
alert('Erreur lors du téléchargement du fichier')
|
||||
}
|
||||
} else {
|
||||
// Ouvrir dans un nouvel onglet pour les autres fichiers (PDF, etc.)
|
||||
window.open(docWithUrl.url, '_blank')
|
||||
|
|
|
|||
Loading…
Reference in a new issue