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
|
// Chercher l'URL dans les données chargées
|
||||||
const docsWithUrls = periodUrls[period]
|
const docsWithUrls = periodUrls[period]
|
||||||
if (docsWithUrls) {
|
if (docsWithUrls) {
|
||||||
|
|
@ -468,13 +468,22 @@ function SectionComptables() {
|
||||||
const isTxtFile = item.title.toLowerCase().endsWith('.txt')
|
const isTxtFile = item.title.toLowerCase().endsWith('.txt')
|
||||||
|
|
||||||
if (isTxtFile) {
|
if (isTxtFile) {
|
||||||
// Forcer le téléchargement pour les fichiers .txt
|
// Forcer le téléchargement pour les fichiers .txt en utilisant fetch
|
||||||
const link = document.createElement('a')
|
try {
|
||||||
link.href = docWithUrl.url
|
const response = await fetch(docWithUrl.url)
|
||||||
link.download = item.title
|
const blob = await response.blob()
|
||||||
document.body.appendChild(link)
|
const blobUrl = window.URL.createObjectURL(blob)
|
||||||
link.click()
|
const link = document.createElement('a')
|
||||||
document.body.removeChild(link)
|
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 {
|
} else {
|
||||||
// Ouvrir dans un nouvel onglet pour les autres fichiers (PDF, etc.)
|
// Ouvrir dans un nouvel onglet pour les autres fichiers (PDF, etc.)
|
||||||
window.open(docWithUrl.url, '_blank')
|
window.open(docWithUrl.url, '_blank')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue