phplaravelvue.jslaravel-vapor

413 request entity too large - PHP Vapor Laravel


Locally it works, when it's in production I can't upload the file, it's a CSV that has a size of 6.8mb, it's hosted on vapor. i'm using vue2dropzone component.

enter image description here

enter image description here


Solution

  • In the documentation, your host indicates that POST requests uploads are capped. With a little overhead from parameters, headers, etc, this means your uploads must be a little under 4.5MB.

    File Uploads

    Due to AWS Lambda limitations, file uploads made directly to your application backend can only be up to roughly 4.5MB in size. This is a hard limit imposed by AWS, and updating the php.ini configuration file or any other configuration will not raise this limit. Therefore, to ensure your application's users won't receive an HTTP 413 Payload Too Large response, you may validate the file upload size using JavaScript before initiating the file upload to your application's backend.

    If your application needs to receive file uploads larger than AWS allows, those files must be streamed directly to S3 from your application's frontend (Browser). To assist you, we've written an NPM package that makes it easy to perform file uploads directly from your application's frontend.

    The solution (which is just one of many, you don't have to use their suggestion) mentioned uses the browser-based laravel-vapor package to upload files to a S3-compatible storage. Authentication is done by having your Laravel app create a URL that can used once to upload a file into a S3 storage bucket. That way, you don't store your credentials in the front-end.

    Alternatively, if you just want to ingest the CSV file without storing it you could choose to upload it in chunks or perhaps stream it to your backend line-by-line.