图像 url 在开发服务器上工作,但在生产服务器上失败

男人

我正在使用 Laravel 5.8 版本开发 API 应用程序。当向productsapi 端点发出 get 请求时,我返回一个如下所示的ProductResource集合

public function toArray($request)
{
    return [
        'id'            => $this->id,
        'name'          => $this->name,
        'category'      => $this->category,
        'description'   => $this->description,
        'status'        => $this->status,
        'price'         => $this->price,
        'barrels'       => $this->barrels,
        'interest'      => $this->interest,
        'start'         => $this->start,
        'end'           => $this->end,
        'hidden'        => $this->hidden,
        'imageUrl'      => asset('storage/images/products/' . $this->image->name)
    ];
}

我面临的挑战是,在我的本地服务器上单击返回imageUrl的图像显示正确的图像,但在登台环境中,我得到了默认的404未找到页面。

我在我正在开发的本地服务器上创建了一个符号链接,public/storage用于storage/app/public在将应用程序文件上传到登台环境之前存储实际的图像文件。快速检查storage/app/public/images/products临时环境中的 会显示图像文件,但我仍然无法从浏览器中查看它。这种行为的可能原因是什么?

这是我的本地和登台环境中的资源示例

本地/开发服务器

{
    "id": 17,
    "name": "test",
    "category": "test",
    "description": "test",
    "status": "test",
    "price": 10990,
    "barrels": 207736,
    "interest": 0.2,
    "start": "2019-07-25",
    "end": "2019-08-25",
    "hidden": 0,
    "imageUrl": "http://localhost:8000/storage/images/products/pramopro_test_17.jpeg"
  }

登台服务器

{
    "id": 13,
    "name": "test prod",
    "category": "test prod category",
    "description": "test prod description",
    "status": "loading",
    "price": 10000,
    "barrels": 300000,
    "interest": 0.2,
    "start": "2019-07-22",
    "end": "2019-08-28",
    "hidden": 0,
    "imageUrl": "http://staging.pramopro.com/storage/images/products/pramopro_testprod_13.jpeg"
  }
穆罕默德·阿克塔

您需要像这样对您的存储文件夹进行符号链接:

ln -s ../project/storage/app/public storage

你将把它运行到你的网站文件而不是public_html文件夹中

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从URL中的node.js服务器文件夹中获取图像?

URL可以在localhost上正常工作,而不能在Web服务器上工作

Laravel在生产服务器上不显示图像

从服务器删除图像

用于从后端服务器访问图像的URL格式

创建从服务器上的URL获得的图像的LinkedResource

从服务器获取图像

如何将服务器图像URL转换为Drawable Int

如何使用URL检查服务器上是否存在图像

在服务器上上传图像

从服务器到TableView XCode的图像URL的数组列表

在服务器上发送图像数组?

如何从硒中的HTTP服务器传递图像URL

如何在iOS中使用url从服务器获取多个图像

将图像上传到服务器并将URL保存到服务器

如何从服务器URL缓存图像并在没有Internet连接的情况下将其显示在ListView上

如何从具有图像URL列表的服务器从JSON中的GridView中加载图像

图像未在片段列表视图适配器上的服务器URL的imageview中渲染

如何使用php或javascript从服务器文件夹中的URL保存图像?

图像上传在服务器中不起作用。在本地主机上工作正常

屏蔽图像 URL 并使其在您的网络服务器上看起来像它

css 背景图像未在 chrome 中显示,但在 atom 实时服务器上工作

NodeJs / React App - 将图像从 url 保存或复制到服务器

从服务器下载图像

我想将图像 URL 作为 json 数据上传到我的角度表单并将其发送到服务器。图像 URL 来自服务器响应

Rails 在生产中生成错误的资产 url(使用 localhost 而不是服务器 ip)

显示带有 Rails 服务器 URL 的图像

.NET Core API - 从服务器而不是从本地存储返回图像 URL

如何将在 Flask 服务器上创建的 PIL 图像下载到我的桌面。Image.save() 仅将其保存到服务器。无法通过 URL 访问图像