Question

413 Payload Too Large for a Serverless Function with > 1MB payload

I have an image-upload Serverless Function that accepts a file (image) to upload to a Spaces Bucket. The function is called from an Anguular client app. The function works well for image files less than 1MB. Trying to submit a file larger than 1MB, I get these errors back:

image-upload.service.ts:102 POST https://faas-fra1-afec6ce7.doserverless.co/api/v1/web/fn-d2086534-a6e4-42a4-95ce-cf3fd0d24652/app/upload-image net::ERR_FAILED 413 (Payload Too Large)

When this happens, there is another CORS error that comes along:

Access to XMLHttpRequest at 'https://faas-fra1-afec6ce7.doserverless.co/api/v1/web/fn-d2086534-a6e4-42a4-95ce-cf3fd0d24652/app/upload-image' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

These only occur for files larger than 1MB, even though the documentation mentions a limit of 5MB.

Please advise. Thanks!


Submit an answer


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!

Sign In or Sign Up to Answer

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.

First, the Payload Too Large (413 Error) occurs because, even though the documentation states a 5MB limit, there might be a default restriction in your DigitalOcean Functions settings. Check if your function’s request body size limit is configurable. If this limit cannot be adjusted, consider uploading large files directly to Spaces from the client instead of passing them through your function.

Second, the CORS issue typically happens when your function doesn’t return the proper Access-Control-Allow-Origin headers. Since this error only appears for files over 1MB, your function might fail before sending a valid response. Ensure your function handles CORS correctly:

> response.setHeader("Access-Control-Allow-Origin", "*");
> response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
> response.setHeader("Access-Control-Allow-Headers", "Content-Type")

If increasing the limit isn’t possible, consider switching to direct client-to-Spaces uploads using pre-signed URLs.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.