App service returning bad gateway

Kartik Deep Sagar 10 Reputation points
2025-02-20T13:26:58.1833333+00:00

Hi

I have a Go api hosted in azure docker. When i post a request without the JWT the api returns unauthorized 401 status however the Azure is converting it to bad gateway.

It is only happening when the request contains multi-part form data. (We don't have any api gateway in our plan)

How do i overcome this issue.

Thanks

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Kartik Deep Sagar 10 Reputation points
    2025-02-20T16:26:11.3866667+00:00

    Hi Alex,

    Thanks for you response.

    It does seem like the issue is related to the file size in form-data. I tried uploading a lower size file and it went through. I am uploading a 5mb file that seems to be causing the issue.

    What do you think where should i update the required stuff. I have a docker image on ubuntu. I am using gin with Go.

    Thanks

    1 person found this answer helpful.

  2. Shree Hima Bindu Maganti 4,925 Reputation points Microsoft External Staff Moderator
    2025-03-10T09:23:24.22+00:00

    Hi @Kartik Deep Sagar
    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.
    sol
    I have fixed it by reading and discarding the multipart form data. That way azure doesn't raise any concern for the request :-)

    func discardMultipartDataIfAny(context *gin.Context) {
    	data, err := context.Request.MultipartReader()
    	if err == nil {
    		for {
    			part, err := data.NextPart()
    			if err != nil || err == io.EOF {
    				break
    			}
    			_, err = io.Copy(io.Discard, part)
    			part.Close()
    			if err != nil {
    				break
    			}
    		}
    	}
    }
    

    If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.
    Please let us know if you need further assistance.

    1 person found this answer helpful.
    0 comments No comments

  3. Kartik Deep Sagar 10 Reputation points
    2025-03-10T08:41:04.6166667+00:00

    Edit: For community I am reposting it as post comment. I accidentally posted it as sub comment previously.

    I have fixed it by reading and discarding the multipart form data. That way azure doesn't raise any concern for the request :-)

    func discardMultipartDataIfAny(context *gin.Context) {
    	data, err := context.Request.MultipartReader()
    	if err == nil {
    		for {
    			part, err := data.NextPart()
    			if err != nil || err == io.EOF {
    				break
    			}
    			_, err = io.Copy(io.Discard, part)
    			part.Close()
    			if err != nil {
    				break
    			}
    		}
    	}
    }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.