问题
I have a project in laravel which one of the sections upload images to the server. Images are saved by using File storage and in the / storage / app / public folder. In local works correctly, the images look good, but when I upload the project to heroku, the images are not seen. Even in heroku run the command "php artisan storage: link"
Why can not I see the images? I would not want to use AWS S3 for this. What could I miss?
Thank you..
回答1:
Heroku doesn't have file storage. So if you're going to use it for your servers you need to figure out another way to store files.
回答2:
In your composer.json add:
"post-install-cmd": [ "ln -sr storage/app/public public/storage" ],
回答3:
Also You can upload images to public folder instead of storage folder (By this way you will not get problems like above ).
for that You need to change config in app/filesystem.php
change
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
to this:
'public' => [
'driver' => 'local',
'root' => public_path(),
'url' => env('APP_URL').'/public',
'visibility' => 'public',
],
and you can store files so:
$pathToFile = Storage::disk('public')->put('uploads/', $file);
now you can insert $pathToFile
variable to DB!
回答4:
In your composer.json
add:
"post-install-cmd": [
"ln -sr storage/app/public public/storage"
]
来源:https://stackoverflow.com/questions/45552264/images-in-app-public-laravel-not-show-in-heroku-app