The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
I'm using the file upload API to upload files to user accounts via a URL. When I post to the upload_url provided by the API endpoint (e.g. "users/1234/files?as_user_id=1234"), it usually returns a 201 HTTP status code. However, I sometimes get a 502 HTTP status code & HTML that looks like this:
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
When I check the progress URL for the upload later, though, it shows that the upload has completed successfully. So it looks like the 502 status code does not indicate an error situation? How do I detect that errors that occur for the post to the upload_url, then?
The 502 Bad Gateway status means that something went wrong. MDN says it's usually something that the user cannot fix, but I can think of at least one place it might be. You might check to make sure that all of the file got transferred correctly and is usable when you download it.
Is there anything specific about when it works and when it doesn't?
For example, does it only happen with larger files? If you're trying to send the contents of a file in the URL, rather than as a separate multipart/form attachment, then you might get the 502 error because the URL is too long.
As far as checking, you can save those that fail and later check the progress URL like you're saying.
I would try to track down the cause of the 502, but sometimes it really is a problem on the server and there's nothing you can do about it. Don't just ignore it and assume everything was successful, though.
James, thanks for the suggestions. Every 502 that I've manually followed up on has successfully uploaded to the users' accounts. The files tend to be large, 100MB or larger, but other files of similar size upload without the 502 error code. So far I don't see a pattern. The status code is being reported, but I just don't see anything wrong when I follow up later. As you note, at this point I don't see anything I can do on my end.
I had a semi-related situation occur today with one of my students. It's not the same situation, but it was a case where she was getting a failure trying to upload a file, so I throw it out there.
She was unable to to upload a 13 KB file when the rest of the class could. When we got looking, it was because she was over her 50 MB quota. We deleted a file and Canvas said she was now at 91% of her 50 MB quota. When she tried to upload it again, it still failed. I reloaded the page and am pretty sure it still didn't work. I went into a folder and uploaded it and it worked. Then I tried to upload it directly into the MyFiles folder and now it worked when it hadn't before.
Files that are uploaded as submissions are not supposed to count against the quota, but files that are uploaded and used as part of discussions or conversation attachments are. This was a discussion upload she was trying to make.
Again, not sure what, if anything that has to do with your case. She wasn't getting the 502 error because she wasn't using the API, but the quota might be coming into play.
James,
Thanks for the suggestion. I am checking for the quota error separately, & it doesn't look like any of the 502 cases were getting anywhere near their quota, which is over 5GB. I can force the quota error to happen under test conditions, & it's not the same as the 502, but the quota limit is certainly something to keep in mind when uploading.
Another thing that is probably nothing, but I noticed that Canvas was having issues with file uploads on Feb 6 and people were getting 502 and 503 errors.
Canvas Status - Some Canvas Users received errors when attempting to upload files into Canvas
Maybe you were seeing the errors before they became aware of it and fixed it?
It's not clear what the context was for those users' errors, but it is possible. The last 502 error I've seen was logged 2/7 in the afternoon.
There was another issue from yesterday where they found out that the 502 error was bigger than they thought and it was affecting pages as well as uploads. They think they have it fixed (again) now, so let's hope that was the issue.
Interesting. We'll see if the fix affects the upload API. I am still logging 502 codes.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in