Heroku,访问laravel存储文件夹 [英] Heroku, accesing laravel storage folder

查看:89
本文介绍了Heroku,访问laravel存储文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击该按钮时,应该在空白页中打开"resume.pdf"文件.它在localhost上可以正常工作,但是在heroku上执行时,效果不佳.我认为路径是错误的,但我不知道应该选择哪个路径.

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

composer.json

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

index.php

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>

在本地主机中访问

在Herokuapp上访问

推荐答案

因此,此答案分为两个部分.

So, this answer has two parts.

第一个是默认情况下storage不可公开访问. 根据文档:

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

要使其可从网上访问,应创建从public/storage到storage/app/public的符号链接.此约定会将您的公共可访问文件保留在一个目录中,当使用零停机时间部署系统(例如Envoyer)时,可以在各个部署之间轻松共享这些文件.

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.

(您可能在本地执行过一次操作,但是忘记了.或者,本地服务器的应用程序主文件夹而不是public子文件夹已用完.)

(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.)

但是...

在Heroku上,文件系统是临时的. 它不是永久性的. 您存储在实例上的文件可以随时 消失.如果您进行新的部署,或者按比例放大/缩小,或者如果Heroku需要重启/替换实例,您的用户已上传到storage的所有文件都将清除.

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.

相反,您需要将用户上传的内容存储在Amazon S3之类的地方,Laravel可以轻松实现.配置好S3密钥后,您就可以执行Storage::disk('s3')之类的操作来与S3配合使用,而不是要使用即将被擦除的本地磁盘.

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.

这篇关于Heroku,访问laravel存储文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆