TKay's avatar
Level 1

Uploading file from laravel application using POST method causing Internal Server Error

I have a simple form ..

<form action="/products" method="POST"
    enctype="multipart/form-data" id="js-upload-form">

             <input type="file" name="csv" id="csv" multiple>
             <button type="submit" class="btn btn-primary btn-flat">Upload Files</button>

    </form>

using routes ...

Route::post('/products', function(Illuminate\Http\Request $request) {
    return 'Got it';
});

Form submitted ... but I get internal server error 500 as response...

am i missing something?

0 likes
7 replies
jlrdw's avatar

Have you searched this forum for uploading as there has been many prior answers to this.

bobbybouwmann's avatar

Well your route is different then your action... '/products/import/csv' and '/products'

3 likes
TKay's avatar
Level 1

Sorry I have changed the route it was a mistake during submission in my post. Corrected like below:

Route::post('/products', function(Illuminate\Http\Request $request) {
    return 'Got it';
} );

Still the same HTTP 500 error code responded. I have tried uploading 70K size photo and 10K size csv file. Is this related to file size?

But I get a black page as reponse. I expected a page should have 'Got it' written on it.

TKay's avatar
Level 1

I have searched the forum but I found nothing related getting HTTP 500 code replied for a file upload. It should be as simple as it is to do in laravel.

davielee's avatar
davielee
Best Answer
Level 11

Based on your provided markup, you're missing the csrf token hidden input. Try adding that and see if that fixes the problem.

3 likes
ankitparmar372's avatar

Don't do in routes file make controller and call function related to this operation.

NickeyGod's avatar

You can't just return a string in laravel. It won't allow that. Try to return an response like this. If you want to return an String just dd.

Route::post('/products', function(Illuminate\Http\Request $request) {
    return response('Got IT!', 200);
} );

Also you need the csrf-token as mentioned above.

1 like

Please or to participate in this conversation.