Dropzone Js:response after upload success
How can i get response after successful upload by dropzone js and Laravel
my upload code at view is:
create.blade.php
<form action="{{url('gallery/post')}}/{{$post->id}}" class="dropzone">
{{ csrf_field() }}
</form>
Route:
Route::get('gallery/{id}','PostController@upload');
Route::post('gallery/post/{id}','PostController@postUpload');
controller:
public function upload($id)
{
$post = Post::find($id);
return view('gallery.create',compact('post'));
}
public function postUpload(Request $request,$id)
{
$destinationPath = 'images';
$extension = $request->file('file')->getClientOriginalExtension();
$fileName = time() . '.' . $extension;
$upload_success = $request->file('file')->move($destinationPath, $fileName);
$image = new Image;
$image->filename = $fileName ;
$image->post_id = $id;
$image->save();
}
This script solve my problem
Dropzone.options.myAwesomeDropzone = {
maxFilesize: 2, // Size in MB
addRemoveLinks: true,
removedfile: function(file) {
// var name = file.name;
// $.ajax({
// type: 'POST',
// url: 'delete.php',
// data: "id="+name,
// dataType: 'html'
// });
var fileRef;
return (fileRef = file.previewElement) != null ?
fileRef.parentNode.removeChild(file.previewElement) : void 0;
},
success: function(file, response) {
//alert(response);
$('#display_images').html(response);
},
error: function(file, response) {
alert(response);
}
};
Please or to participate in this conversation.