Laravel-medialibrary: The current request does not have a file in a key named X

Created on 29 May 2017  路  6Comments  路  Source: spatie/laravel-medialibrary

Hey! Thanks for all the great packages!

The isssue i found:

RequestDoesNotHaveFile in RequestDoesNotHaveFile.php line 12:
The current request does not have a file in a key named /tmp/php5iH3fq

My Routes:

Route::get('/medialibrary', function(){
    return view('test.medialibrary.index');
});

Route::post('/medialibrary', function(Illuminate\Http\Request $request){
    $user = App\User::find(1);
        $user->addMediaFromRequest($request->my_file)
                 ->toMediaCollection('media');

})->name('test.medialibrary.action');

My view :

<form action="{{ route('test.medialibrary.action') }}" enctype="multipart/form-data" method="post" class="form-create">

    <input type="hidden" name="_token" value="{{ csrf_token() }}">

    <div class="form-group">
      <label>{{trans('og.filename')}} *</label>
      <input type="file" class="form-control" name="my_file" required>
    </div>

    <button type="submit" class="btn btn-primary">{{trans('og.button.create')}}</button>

</form>

Thanks

Most helpful comment

See the documentation; https://docs.spatie.be/laravel-medialibrary/v5/introduction

$newsItem->addMediaFromRequest('image')->toMediaCollection('images');

You should use addMediaFromRequest('my_file') instead of addMediaFromRequest($request->my_file).

All 6 comments

See the documentation; https://docs.spatie.be/laravel-medialibrary/v5/introduction

$newsItem->addMediaFromRequest('image')->toMediaCollection('images');

You should use addMediaFromRequest('my_file') instead of addMediaFromRequest($request->my_file).

Thanks for answering this one @bhulsman

Thanks! :+1:

Came up here, in my case was the size of the file was exceeding PHP restrictions.
Happy coding!

@kikoseijo thanks a lot for this !

Came up here, in my case was the size of the file was exceeding PHP restrictions.
Happy coding!

THIS COMMENT SAVED MY LIFE 馃憤

Was this page helpful?
0 / 5 - 0 ratings