Skip to content

Commit

Permalink
fix: force CSV file on windows with firefox (excel file type issue) (#…
Browse files Browse the repository at this point in the history
…2008)

* fix: force CSV file on windows with firefox (excel file type issue)

* add type application/vnd.ms-excel to input file validator too

---------

Co-authored-by: Fufeck <[email protected]>
  • Loading branch information
MaGOs92 and fufeck authored Jan 23, 2025
1 parent ac64a73 commit c322f79
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/FormulaireDePublication/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export default function FormulaireDePublication({ initialHabilitation, initialRe
const currentRevision = await getCurrentRevision(codeCommune)
setCommuneCurrentRevision(currentRevision)
}
catch {}
catch (e) {
setError(e as Error)
}

setCommune({ ...commune, flagUrl: communeFlagUrl })
}
Expand Down Expand Up @@ -185,7 +187,7 @@ export default function FormulaireDePublication({ initialHabilitation, initialRe
onChange={handleFileChange}
label="Déposer ou cliquer ici pour télécharger votre fichier BAL à publier"
hint="Taille maximale: 50 Mo. Format supporté : CSV"
accept={{ 'text/csv': [] }}
accept={{ 'text/csv': [], 'application/vnd.ms-excel': [] }}
maxSize={50 * 1024 * 1024}
/>
) },
Expand Down
2 changes: 1 addition & 1 deletion src/components/ValidateurBAL/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function ValidateurBAL() {
onChange={handleFileChange}
label="Déposer ou cliquer ici pour télécharger votre fichier BAL à publier"
hint="Taille maximale: 50 Mo. Format supporté : CSV"
accept={{ 'text/csv': [] }}
accept={{ 'text/csv': [], 'application/vnd.ms-excel': [] }}
maxSize={50 * 1024 * 1024}
/>
)}
Expand Down
12 changes: 11 additions & 1 deletion src/lib/api-depot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ export async function createRevision(codeCommune: string, file: File): Promise<R
}),
})

// Force content type to be text/csv
// To fix application/vnd.ms-excel issue on Windows and Firefox
const blobFile = new Blob([file as Blob], {
type: 'text/csv',
})

const _file = new File([blobFile], file.name, {
type: 'text/csv',
})

await customFetch(`/api/proxy-api-depot/revisions/${revision._id}/files/bal`, {
method: 'PUT',
headers: { 'Content-Type': 'text/csv' },
body: file,
body: _file,
})

const computedRevision = await customFetch(`/api/proxy-api-depot/revisions/${revision._id}/compute`, {
Expand Down

0 comments on commit c322f79

Please sign in to comment.