I really hope someone can help me with this issue as I've tried everything I know.
The Issue:
Dropzone doesn't upload any images above 3mb instead shows 422 (Unprocessable Entity), images bellow 3mb upload perfectly fine. I've tried everything possible as well as spent plenty of time searching Google, I am receiving the issue both on local machine (Mac OSX using MAMP pro) and on my linux server (ubuntu 14.0). I believe this may be either a laravel or dropzone issue that I cant seem to figure out.
The File I'm trying to upload is straight from a cannon cam, 8mb filenames date+time.JPG, Ive checking the files via saving them as different outputs .jpg, .jpeg, .png however it still fails, they do work if I save them for web and optimize bellow 3mb however I need to be able to upload at least 9mb.
PHP Ini Settings:
upload_max_filesize = 30M
post_max_size = 30M
Form Settings:
Standard laravel open form with crftoken (_token)
DropZone Settings:
Dropzone.options.templateDrop = {
maxFilesize: 30,
maxThumbnailFilesize:15,
acceptedFiles: ".jpeg,.jpg,.png,.gif",
init: function () {
this.on("addedfile", function (file) {
//Show loader whilst uploading
$('.jqueryLoader').show();
});
this.on("complete", function (file) {
//when images are fully uploaded reset div and functions within
if (this.getUploadingFiles().length == 0 && this.getQueuedFiles().length == 0) {
$('#galleryImageHolder').load(document.URL + ' #galleryImageHolder', function(){
galleryFunctions();
$('.jqueryLoader').hide();
});
}
});
}
};
Thanks in advance for any help you can offer.
Kind Regards,
Martyn
Are you doing any server-side validation in Laravel? For example, my Upload Request sets a maximum file size on an upload:
public function rules()
{
$rules = [
'file' => 'max:2048'
];
return $rules;
}
Related
I'm using Laravel 5.4 for my website, and I'm getting a problem when the user tries to upload files bigger than 1MB. This problem doesn't appear on localhost. The error I get is nothing related to the file size, but it's a MethodNotAllowedHttpException in RouteCollection.php line 251. The method I'm using to upload the files is 'PUT'.
I've tried the " $request->file('postpic')->storeAs('/public/post_pic/',$filenametostore);" and the "Storage::putFileAs('public/post_pic', $request->file('postpic'), $filenametostore);" but none of them worked online for files bigger than 1MB.
I also checked the php options on cpanel, and they are set to accept files size of 50MB (max_file_size), a memory_limit of 768MB, a post_max_size of 128MB. I also contacted the hosting server, and after opening a ticket to see what's wrong, I've got an answer that there is a programming bug and the server's configuration is fine. I've spent two days looking for an online solution, but I didn't get any good results about this topic, that's why I'm asking this question here, and I would really appreciate any support to solve it. Finally, I've noticed that when I upload the same 9MB file offline Vs online: looking at the Network tab in the browser, I could find that there were updates about the user's ID and the file Id when uploading this file offline, but online, the network freezes for a while without showing any updates, then the error page appears. When using a smaller file (less than 1.2MB) everything works normally online and offline.
My route is:
Route::PUT('/post/{id}/store',[
'as' => 'storepost',
'uses' => 'PostsController#store'
]);
My controller function is:
public function store(Request $request, $id, loggeduser $lu)
{
$this->validate($request,[
'body'=>'required',
'postpic'=>'nullable|max:40000'
]);
$profile=profile::find($id);
$isvideo=0;
if($request->hasfile('postpic')){
$filenamewithext=$request->file('postpic')->getClientOriginalName();
$filename=pathinfo($filenamewithext,PATHINFO_FILENAME);
$extension=$request->file('postpic')->getClientOriginalExtension();
$filenametostore='1_'.$filename.'_'.time().'.'.$extension;
$orgimage = Storage::disk('local')->putFileAs('public/post_pic', $request->file('postpic'), $filenametostore);
if(substr($request->file('postpic')->getMimeType(), 0, 5) == 'image') {
//Resize image here
$imagepath = public_path('storage/post_pic/'.$filenametostore);
$img = Image::make($imagepath)->resize(700, 400, function($constraint) {
$constraint->aspectRatio();
});
$img->save($imagepath);
}elseif(substr($request->file('postpic')->getMimeType(), 0, 5) == 'video') {
//it's a video
$isvideo=1;
}
}else{
//there is no photo
$filenametostore='0';
}
$logged_user_id=$lu->userid;
$post=new post();
$post->post_pic=$filenametostore;
$post->isvideo = $isvideo;
$post->body=$request->input('body');
$post->user_id=$logged_user_id;
$post->profile_id=$id;
$post->save();
return redirect('/profile/'.$id)->with('success','Your story is alive..');
}
The blade file:
{!!Form::open(['action'=>['PostsController#store','id'=>$profile->id],'method'=>'PUT','enctype'=>'multipart/form-data','files'=>true])!!}
{!! csrf_field() !!}
<input id="postpic" type="file" name="postpic" class="btn btn-primary" style="width:100%;"/>
{{Form::textarea('body','',['class'=>'form-control','required','placeholder'=>'Post a story on your profile..'])}}
{{Form::submit('Post',['class'=>'btn btn-success'])}}
{!!Form::close()!!}
Thank you in advance.
I can upload the files if they are fitting this validation rule
'user_file' => 'file|max:10240|mimes:xls,xlsx,doc,docx,pdf,zip'
all goes fine.
I have set my upload_max_filesize to 32MB and post_max_size to 40MB in php.ini
but if i try to upload a file bigger than 40MB my validation rules don't even trigger. I get TokenMismatchException error....
If someone can verify this by simply trying to upload some very big file (a video file for example)
When You exceed post payload size - everything is dropped, so csrf_token does not come to laravel and the upload file is empty so it cannot be validated.
UPDATE
To fix this you need to check the file size before the uploading with javascript or jquery
here is an example:
How to check file input size with jQuery?
In the case of file uploads, the file has to be copied to temp location into the server then the rules will work. so your server will not allow files of size greater than 40MB (post_max_size) into the temp location so rules will not work.
Instead, to fix this you need to do frontend validation for files.
You can do this using simple Javascript as shown below,
$('input[type="file"]').change(function () {
if (this.files[0] != undefined) {
var name = this.name;
var filesize = this.files[0].size;
var field = $('#' + this.name).parents('.input-group');
//check if file size is larger than 3MB(which is 3e+6 bytes)
if (filesize > 3000000) {
alert(filesize);
//reset that input field if its file size is more than 3MB
$('[name="' + name + '"]').val('')
}
}
});
you can just include this for all input of type='file' by changing size limit in bytes.
I encountered the same problem. You should as well check that the validator is checking file data, not post data :
I've tested :
$validator = Validator::make($request->post(), [
myfield' => 'required|image|mimes:jpeg,png,jpg,gif|max:1000000'
]);
Should have been :
$validator = Validator::make($request->file(), [
myfield' => 'required|image|mimes:jpeg,png,jpg,gif|max:1000000'
]);
I know there are many questions about Request Entity Too Large on internet but i could not find right answer for my problem ;)
I`m using HTML file input tag to let users upload their images .
<input type = 'file' class = 'upload-pic' accept='image/*' id ='Fuploader' name = 'pro-pic'><br>
There is nothing wrong with files less than 2 MB which is allowed by my site
But the problem is if some one decide to upload larger file like 5.10 MB , i can handle it by php and warn user that this file is too large
if($_FILES['pro-pic']['size'] > 2000000)
{
die("TOO LARGE");
}
But my problem is by uploading 5.10 MB file , Request entity too large error will be lunched and rest of my php code won`t work
I have checked post_max_size and upload_max_filesize they are both set to 8MB
But i get Error on 5.10MB !
And I need to find way to handle files even larger than 8MB because there is no way to guess what user may try to upload ;) and i don`t want them to get dirty and broken page because of REQUEST ENTITY TOO LARGE ERROR
Is there any way too fully disable this Error Or set upload_max_filesize and post_max_size to infinity ?
You need to set SecRequestBodyAccess Off.
Check the link i have given ..it would help you
https://serverfault.com/questions/402630/http-error-413-request-entity-too-large
I have a file uploading function on my Symfony2 project.
I am seting the maxSize parameter like that:
$manuscript_file = new File(array(
'maxSize' => '20M',
'mimeTypes' => array(
'application/msword',
'application/zip',
),
'mimeTypesMessage' => 'Please upload a valid manuscript file. Valid types are: doc, docx, zip',
));
The problem is that when I am trying to upload a 2M or 3M word file, I am getting the validation message:
The file is too large. Allowed maximum size is 20M bytes.
Did you faced that? Or is my code wrong.
I took the example from the Symfony documentation:
Symfony File - Validation Constraints Reference
I already faces this issue, so I post this solution (I think this is the same issue for you).
This is a known bug of Symfony, in fact the framework will display the validator error message also when the file size is too high for your PHP configuration, instead of getting the classical PHP error.
In your current PHP config, you probably limited the max upload size to 2M, so Symfony display the wrong error.
So check your php.ini file (/etc/php5/apache2/php.ini on Linux) and increase max_upload_size to fit your field :
upload_max_filesize = 20M
Don't forget to restart apache : apache2ctl restart
Now it should work !
Note that's probably fixed on the last Symfony version, another solution is perhaps to upgrade your project to sf2.3 (but i'm not sure of that) ^^
I created a jQuery validation method to prevent sending big files to server because php don't valide it (It is in Spanish):
$(function() {
//Validate 20MB
validarFileSize('#carga_telefonos_form_file', {{ 10*1024*1024 }}, '#div-mensaje-file-size', '#botonSubmit');
});
function validarFileSize(campo, maximo, divMensaje, btnGuardar) {
console.debug("validarFileSize. Campo: " + campo + ", maximo: " + maximo);
$(campo).bind('change', function() {
var size = this.files[0].size;
if (size > maximo) {
$(divMensaje).show();
$(btnGuardar).attr('disabled', 'disabled');
} else {
$(divMensaje).hide();
$(btnGuardar).removeAttr('disabled');
}
});
}
If you are using POST to upload your file, beware with post_max_size limit in php.ini
I am using a script to upload photo (written by my own) which allow user to select more than 1 files, using Flash.
When user click upload, as3 will post the upload file to upload.php, resize it, and save it one by one.
The problem:
In production server, if I am uploading many photos and the photos size are very large, >2MB, the uploading progress just stuck in halfway, only the first few photos successfully uploaded.
What I have found out:
If I tried with smaller size photos, or if I disabled the resizing script in upload.php, there are no problem at all.Furthermore, the script work fine in my localhost with newer processor compared to the problematic server with older model)
The resize script is simple. It just check whether the image resolution is large, and use imagecopyresampled() to resize the image if needed.
I tried to unset image resource in upload.php to free up memory but it doesn't help.
What else could be the problem?
If I remember right, there is a 2mb upload limit in php, you can change it in the php.ini file.
I solved the problem.
It happens when I use code like this in AS3:
for(var i:Number = 0; i< fileList.length; i++) {
fileList[i].upload(new URLRequest(param.uploadURL+"&sessionid="+param.session_id));
}
The code seems like pushing upload.php script in very tedious way.
I made changes to both my AS3 and JS, so that JS call to AS3 upload() function only everytime a file upload is completed (from event listener EVENT.COMPLETE)
By making so, AS3 wont call for upload.php synchronously for multiple files. Instead, it wait for a file completed the upload, then call for another upload for the next file.