Sunday, April 2, 2017

Dropzone.JS in form with Laravel 5.2 not saving file

been stuck on this issue with saving the uploaded file to the Database using DropzoneJS.

The error in this case is that it's posting all the other form data except for the uploaded file which returns an empty response although I'm not sure what I'm missing here.

If anyone can manage to spot the error, it would be greatly appreciated!

View

<form action="" method="POST" class="form-horizontal" role="form">
<meta name="csrf-token" content="" />
<input type="hidden" name="_token" value="">
<div class="form-group">
    <legend></legend>
</div>

<label for="title">Title</label>
<input type="text" name="title" id="input-title" class="form-control">

<label for="description">Description</label>
<input type="text" name="description" id="input-description" class="form-control">

<div class="dropzone dropzone-previews" id="my-awesome-dropzone">
    <input name="_token" type="hidden" value="">
</div>

Jquery

<script type="text/javascript">
        Dropzone.autoDiscover = false;
        var myDropzone = new Dropzone("#my-awesome-dropzone",{
            url: "/save_information",
            uploadMultiple: true,
            autoProcessQueue: false,
            addRemoveLinks: true,
            paramName: "file", // The name that will be used to transfer the file
            maxFilesize: 10, // MB
            sending: function(file, xhr, formData) {
                formData.append("_token", "");
            }
        });


        $('#submit-all').click(function(){
            e.preventDefault();
            myDropzone.processQueue();
        });

controller function

 if (Request::hasFile('filename')) {
        $image = Request::file('filename');
        $location = public_path('images/');
        $filename = time() . '.' . $image->getClientOriginalExtension();
            $image->move($location, $filename);

            $trustDocument->image = $filename;

        } else {
        dd('no image found');
    }

$trustDocument->save();



via n31l

Advertisement