api: refactor image size in composeImageHandler

The composeImageHandler no longer needs to get the file size for an
Image because the image struct now contains the file size.
This commit is contained in:
Jacob Kozol 2019-10-27 18:32:12 +01:00 committed by Tom Gundersen
parent 4366e390cf
commit eeb657fb5b

View file

@ -854,15 +854,9 @@ func (api *API) composeImageHandler(writer http.ResponseWriter, request *http.Re
return
}
stat, err := image.File.Stat()
if err != nil {
statusResponseError(writer, http.StatusInternalServerError)
return
}
writer.Header().Set("Content-Disposition", "attachment; filename="+uuid.String()+"-"+image.Name)
writer.Header().Set("Content-Type", image.Mime)
writer.Header().Set("Content-Length", fmt.Sprintf("%d", stat.Size()))
writer.Header().Set("Content-Length", fmt.Sprintf("%d", image.Size))
io.Copy(writer, image.File)
}