Merged in feature/download-pdf (pull request #216)
retrieve document by id and tests * working * missing files
This commit is contained in:
@@ -15,6 +15,23 @@ import (
|
||||
openapi_types "github.com/oapi-codegen/runtime/types"
|
||||
)
|
||||
|
||||
// DownloadDocument streams the original uploaded document file to the client.
|
||||
func (s *Controllers) DownloadDocument(ctx echo.Context, id DocumentID) error {
|
||||
result, err := s.svc.DocumentDownload.GetDownload(ctx.Request().Context(), uuid.UUID(id))
|
||||
if err != nil {
|
||||
slog.Error("unable to download document", "error", err, "document_id", id)
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to download document: %s", err))
|
||||
}
|
||||
defer result.Body.Close()
|
||||
|
||||
ctx.Response().Header().Set("Content-Disposition",
|
||||
fmt.Sprintf(`attachment; filename="%s"`, result.Filename))
|
||||
ctx.Response().Header().Set("Content-Length",
|
||||
fmt.Sprintf("%d", result.Size))
|
||||
|
||||
return ctx.Stream(http.StatusOK, result.ContentType, result.Body)
|
||||
}
|
||||
|
||||
func (s *Controllers) UploadDocument(ctx echo.Context, clientId ClientID) error {
|
||||
form, err := ctx.MultipartForm()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user