fix: reduce memory usage
This commit is contained in:
parent
0d56779189
commit
939f14eb86
2 changed files with 4 additions and 4 deletions
|
@ -46,7 +46,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.ParseMultipartForm(10240 << 20)
|
err := r.ParseMultipartForm(10 << 20)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.Render(w, r, &commonErrors.ErrResponse{
|
render.Render(w, r, &commonErrors.ErrResponse{
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
|
@ -57,7 +57,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
files := r.MultipartForm.File["files"]
|
files := r.MultipartForm.File["files"]
|
||||||
for _, fileHeader := range files {
|
for _, fileHeader := range files {
|
||||||
if fileHeader.Size > (1024 << 20) {
|
if fileHeader.Size > (4096 << 20) {
|
||||||
render.Render(w, r, &commonErrors.ErrResponse{
|
render.Render(w, r, &commonErrors.ErrResponse{
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
StatusText: "File too large",
|
StatusText: "File too large",
|
||||||
|
|
|
@ -86,7 +86,6 @@ func (s *Service) Upload(input *TaskUploadInput) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't open fileHeader %w", err)
|
return fmt.Errorf("can't open fileHeader %w", err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
if !strings.HasSuffix(fileHeader.Filename, ".rpm") {
|
if !strings.HasSuffix(fileHeader.Filename, ".rpm") {
|
||||||
return fmt.Errorf("invalid file type: only .rpm files are allowed")
|
return fmt.Errorf("invalid file type: only .rpm files are allowed")
|
||||||
|
@ -107,12 +106,13 @@ func (s *Service) Upload(input *TaskUploadInput) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer outFile.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(outFile, file)
|
_, err = io.Copy(outFile, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
outFile.Close()
|
||||||
|
file.Close()
|
||||||
|
|
||||||
pkg, err := rpm.Open(filePath)
|
pkg, err := rpm.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue