Skip to content

[FEAT][API] Download a report #85

@youen

Description

@youen

Description

Allow to download a report

Request

Method

GET

URL

/reports/:id/download

Request Parameters

  • id: the report ID, required

Request Body

None

Result

Result parameters

None

Result Body

The report file

Example Curl Request

Request

curl -X GET "http://localhost:8080/reports/:id/download"

Curl Response

(file content)

Go server

Struct

type DownloadReportRequest struct {
    ID string `json:"id" format:"uuid"`
}

Handler

func (s *Server) handleDownloadReport(w http.ResponseWriter, r *http.Request) {
    var req DownloadReportRequest
    if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    report, err := s.store.GetReport(req.ID)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    // Serve the report file
    w.Header().Set("Content-Type", "application/octet-stream")
    w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.pdf", report.Name))
    w.Write(report.Data)
}
}

w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", report.Name))
if _, err := w.Write(report.Data); err != nil {
	http.Error(w, "Internal server error", http.StatusInternalServerError)
	return
}

}

## Links

 - [Reports.download_report](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1048)
 - [Any](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1048)


## Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project [avatar-python](https://github.com/octopize/avatar-python/) to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions