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!
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.
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:
If increasing the limit isn’t possible, consider switching to direct client-to-Spaces uploads using pre-signed URLs.