This is my route:
Route::post('/articles/image/upload','ArticleController@imageUpload');
This is my controller:
public function imageUpload(Request $request){
$path=$request->file('wangEditorH5File')->store('/');
return asset('storage/'.$path);
}
I am using rich text editor to allow a user to upload their image so I have to return a url to the text editor.
I made a symbolic link using:
php artisan storage:link
that creates a symlink from public/storage
to storage/app/public
.
I also changed the default drive of filesystem from local to public before linked
return [
'default' => env('FILESYSTEM_DRIVER', 'public'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
After all is set, the text editor returns an error message that tells me I can not get the url of the image.
It means I can't access the storage
folder under public
.
I tried to put an image in the css folder and change the asset()
function
public function imageUpload(Request $request){
$path=$request->file('wangEditorH5File')->store('/');
return asset('css/111.jpg');
}
It works for css and image shows up.