Skip to content

Commit

Permalink
fix: download data asset bug for file type && file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Nov 13, 2024
1 parent 65e2173 commit 25288f0
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions client/data_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ func (u *DataAssetImpl) Share(id int64, shareDetails []ShareDataAssetRequest) ([
}

func (u *DataAssetImpl) Download(id int64) (*FileResponse, error) {

dataAsset, _ := u.Get(id)

resp, err := u.Config.Client.R().SetPathParam("id", fmt.Sprintf("%v", id)).
SetOutput("temporary-file").
Get(DownloadDataAssetByID)
Expand All @@ -255,14 +258,9 @@ func (u *DataAssetImpl) Download(id int64) (*FileResponse, error) {
return nil, fmt.Errorf("failed to download file: %w", err)
}

contentDisposition := resp.Header().Get("Content-Disposition")
var fileName string
if contentDisposition != "" {
_, params, err := mime.ParseMediaType(contentDisposition)
if err == nil {
fileName = params["filename"]
}
}
var fileName = dataAsset.Name

mediaType, _, err := mime.ParseMediaType(dataAsset.Type)

if fileName == "" {
fileName = filepath.Base(resp.Request.URL)
Expand All @@ -275,12 +273,10 @@ func (u *DataAssetImpl) Download(id int64) (*FileResponse, error) {

defer os.Remove("temporary-file")

fileType := filepath.Ext(fileName)

return &FileResponse{
FileName: fileName,
FileContent: fileContent,
FileType: fileType,
FileType: mediaType,
}, nil

}

0 comments on commit 25288f0

Please sign in to comment.