huma
huma copied to clipboard
How to return files over output?
In echo, I usually do this:
c.Response().Header().Set("Content-Type", "application/pdf")
if err := generatePDFInvoice(c.Request().Context(), params, c.Response().Writer); err != nil {
return err
}
return nil
How do I respond with files in body in Huma? The docs do not have such an example
@stargeneration-winston take a look at https://huma.rocks/features/response-outputs/#body. You can use a type of []byte for the body if the file fits in memory, otherwise you can use https://huma.rocks/features/response-streaming/ to get the response writer.
https://go.dev/play/p/IV3P5XEJrHV
Hope that helps!
@stargeneration-winston take a look at https://huma.rocks/features/response-outputs/#body. You can use a type of
[]bytefor the body if the file fits in memory, otherwise you can use https://huma.rocks/features/response-streaming/ to get the response writer.https://go.dev/play/p/IV3P5XEJrHV
Hope that helps!
So I need to send file responses are streaming responses?