Report this

What is the reason for this report?

File Upload issues via HTTP REST API

Posted on March 25, 2020

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.



This textbox defaults to using Markdown to format your answer.

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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Can you resolve this? please tell us how u did…

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.