2

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!

8
  • 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? Commented Oct 2, 2015 at 8:04
  • @Jeemusu Hi! i updated my Question Commented Oct 2, 2015 at 8:07
  • Could be unlikely but worth checking, do you have any conflicting routes in your routes.php file? Commented Oct 2, 2015 at 8:09
  • I checked my routes file. No conflicting routes, thanks. Commented Oct 2, 2015 at 8:12
  • @musicvicious you don't have a POST route. Commented Oct 2, 2015 at 8:27

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Do you have a FORM element on the page? It could be that the fileupload script uses the forms method attribute? Are you using POST for your update form, and not PLACE or PUT?
I have a form element on the page, yes. But the input is outside the form tags.
It's obviously not using POST, which is odd. Try using Route::place or Route::put and narrow it down to see which method it's using, then you can try and identify where it's coming from.
var_dump(Request::method()) results in "POST"; man, i really don't understand.
but it should not be any.
0

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'
]);

1 Comment

No. the create and edit URI's are used to GET the form (and form data). The store and update methods are POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.