Laravel upload files to Heroku
Actually when you upload the files to the Laravel, it works. I mean, the file is being uploaded but it is not accessible.
Yes, The file is being uploaded when you do so but file is not accessible to the internet because of security purpose. We need to tell the Laravel to make the uploaded file accessible to the internet or public.
There is one solution of this and you know that but you can approach that one solution in two different way.
Do you know one thing?
You know the exact solution and you have solved this problem in your past while doing local development.
This is happening because of Symbolic link, If you remember you create symbolic link while doing local development. You need to do the same thing in Heroku server also.
Approach 1 #
heroku run bash php artisan storage:link
heroku run bash will open the bash of heroku in your terminal. Once Heroku CLI is opened you can create Symbolic link and your storage directory will become public.
Now you can access the file which you uploaded to the storage because of Symbolic link.
Copy the command from below
php artisan storage:link: I am sure you run this command in the local development also.
Approach 2 #
heroku run /app/php/bin/php /app/www/artisan storage:link
If you are interested in understanding the logic then here is the explanaiton .
Heroku run allow us to run bash command on heroku terminal(machine).
- /app/php/bin/php this is path of php executable (EQUIVALENT TO php)
- /app/www/artisan this is equivalent to artisan (EQUIVALENT TO artisan)
- storage:link this will create Symbolic link to make storage accessible from public directory.
I hope now your problem is solved and you can see your uploaded file.