Question

File Upload issues via HTTP REST API

Posted March 25, 2020 108 views
APIDockerGo

I’m using 5$/m VPS (1 GB RAM) and run docker container with my Golang application.

I have REST API endpoint to upload an image (limited to 5mb), which I upload to Spaces straight forward.

The problem is that it works fine with small images, like 50-100 kb, but when I try to upload 650kb image, I receive following error: multipart: NextPart: bufio: buffer full

The code that handles uploading:

// Limit Upload File Size
    c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, MAX_UPLOAD_SIZE)

    fileHeader, err := c.FormFile("file")
    if err != nil {
        c.JSON(http.StatusBadRequest, &uploadResponse{
            Status: "error",
            Msg:    err.Error(),
        })
        return
    }

    file, err := fileHeader.Open() // IT BREAKS HERE
    if err != nil {
        c.JSON(http.StatusBadRequest, &uploadResponse{
            Status: "error",
            Msg:    err.Error(),
        })
        return
    }
    defer file.Close()

Have you any ideas what can go wrong?

P.S. I mock Spaces localy with localstack’s S3, and all images works just fine. But this same images cause this problem on my VPS.

0 answers
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!