Skip to content

Commit

Permalink
fix: encoding issue for csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jul 26, 2023
1 parent f271a2f commit ec34918
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions controllers/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/crawlab-team/crawlab-core/interfaces"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)

var ExportController ActionController
Expand Down Expand Up @@ -117,7 +116,6 @@ func (ctx *exportContext) getExportDownload(c *gin.Context) {
return
}
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", exp.GetDownloadPath()))
c.Header("Content-Length", strconv.Itoa(len(exp.GetDownloadPath())))
c.File(exp.GetDownloadPath())
}

Expand Down
8 changes: 8 additions & 0 deletions export/csv_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ func (svc *CsvService) export(export *entity.Export) {
return
}

// write bom
bom := []byte{0xEF, 0xBB, 0xBF}
_, err = csvFile.Write(bom)
if err != nil {
trace.PrintError(err)
return
}

// write csv header row
columns, err := svc.getColumns(query, export)
err = csvWriter.Write(columns)
Expand Down

0 comments on commit ec34918

Please sign in to comment.