How to implement Blueimp with Laravel 5

Spent few hours trying to figure out how to implement blueimp image upload with laravel 5. After lot of trial and error finally i'm able to implement.

So here it goes.
1. Download blueimp from source. https://github.com/blueimp/jQuery-File-Upload
2. Create controller in laravel php artisan make:controller UploadController you can name your controller anything for me it's UploadController.
3. Copy class content of https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/UploadHandler.php into UploadController.
4. On laravel's routes.php create your ajax call for me it's
[code]
Route::post('user/upload', function(){
//Points to custom folder
$options['upload_url'] = url('/images/uploads/');
//Uploads custom folder
$options['upload_dir'] = public_path().'/images/uploads/';
//Create handler with options
$upload_handler = new App\Http\Controllers\UploadController($options);
});
[/code]
5. one important thing to remember is exclude above url from CSRF token.
app\Http\Middleware\VerifyCsrfToken.php
add your rout to except array
protected $except = [
        'user/upload'
    ];
6. Then include all necessary files and on your field run fileupload function on js. It has good explanation on it's documentation.

Comments

  1. Is the upload blade is resources/views/images/uploads/index.blade.php?

    I copy the upload index.html into the path

    then I got a error
    Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
    No message

    Can you save my day~thanks~

    ReplyDelete

Post a Comment

Popular posts from this blog

Set up RAID on Dell Poweredge 2850

HackUB (Hackathon Ulaanbaatar) - Organizing event