简体   繁体   English

Laravel-无法使用Nginx从Ubuntu服务器上的存储下载文件

[英]Laravel - Can't download file from storage at Ubuntu server with Nginx

So I'm testing that a Laravel app that I just deployed to an Ubuntu server with Nginx works correctly, and I reached a point where I need to download some files that were upload from the front end using Angular. 因此,我正在测试刚刚使用Nginx部署到Ubuntu服务器的Laravel应用程序是否可以正常工作,并且达到了需要下载一些使用Angular从前端上传的文件的地步。

I can upload files with no problem and I made sure that those are actually in the server and yeah, they are saved as expected. 我可以毫无问题地上传文件,并且确保文件确实在服务器中,是的,它们已按预期保存。

However when I need to download them I get the error: "Failed to create the file" 但是,当我需要下载它们时,出现错误:“无法创建文件”

It worked on my local machine, so I'm guessing is kind of a configuration problem but I'm not sure what to change yet. 它可以在我的本地计算机上运行,​​所以我猜是一个配置问题,但是我不确定要更改什么。

The file is being requested through a GET request with Http with the header: { responseType: ResponseContentType.Blob }, the latter being part of Angular. 通过带有Http的GET请求来请求该文件,其标题为:{responseType:ResponseContentType.Blob},后者是Angular的一部分。

And in Laravel this is how I'm returning the file: 在Laravel中,这就是我返回文件的方式:

public function download($activityId) {
    $activity = $activity = Activity::find($activityId, ['student_id', 'file_storage']);

    $file = public_path() . '/storage/activityFiles/' . $activity['student_id'] . '/' . $activity['file_storage'];

    return response()->download($file);
}

What can I be missing? 我会缺少什么?

I decided to take a look at the laravel logs to see a little further the problem. 我决定看一下laravel日志,以进一步了解问题所在。

The problem was that I forgot to create the symbolic link to the storage. 问题是我忘了创建到存储的符号链接。

That fixed the issue. 这解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM