snipesnipes's avatar

Tinymce image upload

Hello , Iwas using php before to do this and it worked fine. Now in Laravel it seems I cant do this .

heres the tinymce :

    image_title: true,
    automatic_uploads: true,
    images_upload_url: '{{url("/upload")}}',
    file_picker_types: 'image',
    file_picker_callback: function(cb, value, meta) {

        var input = document.createElement('input');
        input.setAttribute('type', 'file');
        input.setAttribute('accept', 'image/*');

        input.onchange = function() {
            var file = this.files[0];

            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function () {
                var id = 'blobid' + (new Date()).getTime();
                var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
                var base64 = reader.result.split(',')[1];
                var blobInfo = blobCache.create(id, file, base64);
                blobCache.add(blobInfo);
                cb(blobInfo.blobUri(), { title: file.name });
            };
        };
        input.click();
    }

});

the route:

Route::get('/upload' , 'MembersController@upload');

the controller :

public function upload(Request $request) {

    $file=$request->file('file');
    $path= url('/blogfile/').'/'.$file->getClientOriginalName();
    $imgpath=$file->move(public_path('/blogfile/'),$file->getClientOriginalName());
    $fileNameToStore= $path;


    return json_encode(['location' => $fileNameToStore]);

}

it returns error 405 Method Not Allowed

can someone explains to me how this can work ? thx

0 likes
2 replies
itsfg's avatar
itsfg
Best Answer
Level 5

Hi @snipesnipes

I see you use Route::get('/upload' , 'MembersController@upload');

I guess it should be a post route ? Route::post('/upload' , 'MembersController@upload');

snipesnipes's avatar

lol ur right . thx .. note to myself " quit drinking at work for 2020"

:D

Please or to participate in this conversation.