413 request entity too large - PHP Vapor Laravel - php

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.

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.

It can have several reasons.
you should to check:
php configuration file (php.ini).
upload_max_filesize
post_max_size
Apache web service configuration like if your server use from apache service (httpd.conf, .htaccess):
edit this values:
post_max_size
upload_max_filesize
LimitRequestBody
Or if your server works with nginx service you can check nginx.conf file.
edit this value:
client_max_body_size

Related

How to change php config in php.ini & post_max_size in laravel vapor? I'm facing error 413 Request Entity Too Large

How to changes php config & post_max_size setting in laravel vapor?
I'm facing error 413 Request Entity Too Large when trying to upload image on AWS S3.
Application is using Angular as frontend & Laravel is used for backend API.
I'm able to upload image size upto 200-250 KB on AWS-S3 but can't able to upload even 1MB file. Also, there is no validation error on backend API side.
As it is serverless. So, I'm not able to find the setting for php.ini and related settings.
You can override the php variables using Docker runtime
Docker Runtimes Docker based runtimes allow you to package and deploy
applications up to 10GB in size and allow you to install additional
PHP extensions or libraries by updating the environment's
corresponding .Dockerfile. For every new Docker based environment,
Vapor adds a .Dockerfile file that uses one of Vapor's base images as
a starting point for building your image. All of Vapor's Docker images
are based on Alpine Linux:
https://docs.vapor.build/1.0/projects/environments.html#runtime
# Update the `php.ini` file...
# Requires a `php.ini` file at the root of your project...
COPY ./php.ini /usr/local/etc/php/conf.d/overrides.ini
Request Entity Too Large errors with Vapor usually means that Lambda isn't able to handle uploads of that size. I would expect the upper limit to be a bit higher than the 1MB you're reporting, but generally I go straight to uploading images/files directly to S3 from the front end no matter the size to avoid this cropping up.
There is a frontend package provided by the Vapor team that can help with this, which can be installed with npm i -D laravel-vapor.
More information on the package here: https://docs.vapor.build/1.0/resources/storage.html#installing-the-vapor-npm-package
And more information on file uploads to Laravel Vapor from the docs here:
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.
https://docs.vapor.build/1.0/resources/storage.html#file-uploads

PHP Upload/Download size limit for files

I would like to understand if this application is suitable for Apache/PHP.
I want to do something like WeTransfer service where I upload a big file to this web application and it makes a public web link to download the file.
I have some doubt about the streaming/buffering capabilities of Apache/PHP web server.
Can you confirm that if I want to upload or download a file of 2GB with a PHP script I need to set at least the same memory_limit because POST data is not buffered?

Upload Large file from My computer to S3 Server without editing php.ini

I want to upload a large file from My computer to S3 Server without editing php.ini. Firstly,I choose file from browse button and submit upload button and then upload to s3 server. But I can't post form file data when I upload a large file. But I don't want to edit php.ini.Is there any way to upload a large local file to s3 server?
I've done this by implementing Fine Uploader's php implementation for S3. As of recently it is through an MIT license. It's an easy way to upload huge files to S3 without changing your php.ini at all.
It's not the worst thing in the world to set up. You'll need to set some environment variables for the public/secret keys, set up CORS settings on the bucket, and write a php page based on one of the examples which will call a php endpoint that'll handle the signing.
One thing that was not made obvious to me was that, when setting the environment variables, they expect you to make two separate AWS users with different privileges for security reasons.
ini_set("upload_max_filesize","300M");
try this

php temp file upload directory - off local server

When uploading an image PHP stores the temp image in a local on the server.
Is it possible to change this temp location so its off the local server.
Reason: using loading balancing without sticky sessions and I don't want files to be uploaded to one server and then not avaliable on another server. Note: I don't necessaryly complete the file upload and work on the file in the one go.
Preferred temp location would be AWS S3 - also just interested to know if this is possible.
If its not possible I could make the file upload a complete process that also puts the finished file in the final location.
just interested to know if the PHP temp image/file location can be off the the local server?
thankyou
You can mount S3 bucket with s3fs on your Instances which are under ELB, so that all your uploads are shared between application Servers. About /tmp, don't touch it as destination is S3 and it is shared - you don't have to worry.
If you have a lot of uploads, S3 might be bottleneck. In this case, I suggest to setup NAS. Personally, I use GlusterFS because it scales well and very easy to set up. It has replication issues, but you might not use replicated volumes at all and you are fine.
Another alternatives are Ceph, Sector/Sphere, XtreemFS, Tahoe-LAFS, POHMELFS and many others...
You can directly upload a file from a client to S3 with some newer technologies as detailed in this post:
http://www.ioncannon.net/programming/1539/direct-browser-uploading-amazon-s3-cors-fileapi-xhr2-and-signed-puts/
Otherwise, I personally would suggest using each server's tmp folder for exactly that-- temporary storage. After the file is on your server, you can always upload to S3, which would then be accessible across all of your load balanced servers.

What are the changes I have to made in php.ini to move the uploaded files to a remote server?

My php application is running in a master-slave server with load balance. Some times the upload request will redirect to the slave server and the files will uploaded to the slave only. It will not sync with the master. I want to change the file upload path of the apache server of slave to master. What should I do in php.ini to achieve this without making modification in my application?
php.ini can't deal with that (as far as I know). The only options I can think of are:
a) The only solution I've used is to have a separately mounted file system to upload file to - so either system can upload the files to essentially the same place. (Make sure the file_system in in the base dir restrictions is you have them enabled - so oyu many need ot mod php.ini for that.)
b) The load balancer needs to redirect calls of one type to always the same server (i.e. the master). I'm no expert on load balancing so don't know if this is possible.
(And c, that your question rules out, is to split the application into two.)

Categories