Hclee
Hclee

Reputation: 53

Heroku, accesing laravel storage folder

When the button clicked, it is supposed to open a file of "resume.pdf" in a blank page. It works fine with localhost, but when it is executed on heroku, it doesn't go through well. I think the path is wrong but I have no idea which path should be.

composer.json

"post-install-cmd": [
  "php artisan clear-compiled",
  "php artisan optimize",
  "chmod -R 775 public/",
  "chmod -R 775 storage/"
],

index.php

<a class="btn btn-xl btn-outline-light" href="storage/resume.pdf" target="_blank">
    <i class="fa fa-folder-open-o mr-2"></i>
    View Resume!
</a>

Accessed in Localhost

Accessed on Herokuapp

Upvotes: 0

Views: 6204

Answers (1)

ceejayoz
ceejayoz

Reputation: 180023

So, this answer has two parts.

The first is that storage isn't publicly accessible by default. Per the docs:

To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.

(You probably did this locally once, but forgot. Or, your local server is running out of the app's main folder instead of the public subfolder.)

BUT...

On Heroku, the filesystem is ephemeral. It is not permanent. Files you store on the instance can go away at any time. If you do a new deploy, or if you scale up/down, or if Heroku needs to restart/replace an instance, alllllll the files your users have uploaded to storage are wiped out.

Instead, you'll want to store user uploads somewhere like Amazon S3, which Laravel makes easy. Once you've configured your S3 keys, you can just do stuff like Storage::disk('s3') to work with S3 instead of the local, soon-to-be-erased disk.

Upvotes: 2

Related Questions