spatie/laravel-medialibrary

The current request does not have a file in a key named X

Closed this issue ยท 8 comments

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

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! ๐Ÿ‘

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 ๐Ÿ‘

boryn commented

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

For me it was the same problem, you can read the exact error with $request->files->get('image')->getErrorMessage();
where I got The file ... exceeds your upload_max_filesize ini directive (limit is 2048 KiB)

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

For me it was the same problem, you can read the exact error with $request->files->get('image')->getErrorMessage();
where I got The file ... exceeds your upload_max_filesize ini directive (limit is 2048 KiB)

Thank you very much, when i made dd($request->files->get('image')->getErrorMessage()) on this I got message that i have change upload_max_size in php.ini.