2
votes

I have a problem when trying to upload an image via bluimp's jQueryFileUpload.

In my routes i have this: Route::post('image/upload/{folder}', 'ImageController@upload');

my file input that is outside the <form> tags because it is independent to the form:

<input id="imageupload" type="file" name="image" multiple="" data-url="{{ url('admin/image/upload/members') }}" >

my jQuery function points to the data-url attribute value.:

  $('#imageupload').fileupload({
        dataType: 'json',
        maxFileSize: 5000000,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        done: function (e, data) {
            Members.handle_image(data);
        }
   });

The weird thing is that when i call this method from example.app/admin/members/create it works, but when i'm trying to access it from example.app/admin/members/1/edit i get a 405, Method not allowed.

In both cases, the Method is POST.

My routes for create and edit URIs:

Route::get('members/create', [
    'uses' => 'MembersController@create', 'as' => 'admin/members/create'
]);
Route::get('members/{member}/edit', [
    'uses' => 'MembersController@edit', 'as' => 'admin/members/edit'
]);

I'm sure is something really stupid that i can't see.

PS. I have a Project resource, where i also upload images, using the same route and function. It works on both cases (create and edit).

Anybody had this problem ?

Thank you!

2
what are your routes for that uri? what does your form declaration look like? Are you sure your using POST, and not PLACE or PUT? - Jeemusu
@Jeemusu Hi! i updated my Question - musicvicious
Could be unlikely but worth checking, do you have any conflicting routes in your routes.php file? - haakym
I checked my routes file. No conflicting routes, thanks. - musicvicious
@musicvicious you don't have a POST route. - Jeemusu

2 Answers

2
votes

Ok, i managed to solve this, but really i don't understand why it was not working.

In my routes i have this, where the ajax url points as POST:

Route::post('image/upload/{folder}', 'ImageController@upload');

This did not work. I changed it to:

Route::any('image/upload/{folder}', 'ImageController@upload');

And now it works.

It is strange because on my request headers i have POST method, but with post (in routes) i did not work.

0
votes

HTTP 405 indicates that the request method is not supported.

Both of your routes listen for get requests

Route::get('members/create', [
    'uses' => 'MembersController@create', 'as' => 'admin/members/create'
]);
Route::get('members/{member}/edit', [
    'uses' => 'MembersController@edit', 'as' => 'admin/members/edit'
]);

are you sure that you don't want one, or both to be post?

Route::post('members/create', [
    'uses' => 'MembersController@create', 'as' => 'admin/members/create'
]);
Route::post('members/{member}/edit', [
    'uses' => 'MembersController@edit', 'as' => 'admin/members/edit'
]);