【问题标题】:Error user uploading file on Heroku but not local错误用户在 Heroku 上上传文件但不是本地文件
【发布时间】:2020-10-21 06:21:49
【问题描述】:

我有一个应用程序,用户可以在其中上传图片文件。我使用 s3 进行存储。在我的本地机器上,这工作正常,但是当我部署到 Heroku 时,每次我尝试上传(通过单击我的应用程序中的表单按钮)我都会收到一条错误消息,提示““文件不存在或不可读”。它在这行代码上崩溃:

$path = Storage::disk('s3')->put('images/profile', request('image'));

问题似乎在于 put 方法的输入。我在那行代码之前做了一个转储并按请求('image')死了。在我的本地副本上,我看到的是:

Illuminate\Http\UploadedFile {#1236 ▼
  -test: false
  -originalName: "gary-bendig-6GMq7AGxNbE-unsplash.jpg"
  -mimeType: "image/jpeg"
  -error: 0
  #hashName: null
  path: "C:\xampp\tmp"
  filename: "phpD90.tmp"
  basename: "phpD90.tmp"
  pathname: "C:\xampp\tmp\phpD90.tmp"
  extension: "tmp"
  realPath: "C:\xampp\tmp\phpD90.tmp"
  aTime: 2020-06-30 20:09:05
  mTime: 2020-06-30 20:09:05
  cTime: 2020-06-30 20:09:05
  inode: 5629499534269665
  size: 2328835
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\xampp\tmp\phpD90.tmp"
}

这是我在 Heroku 上看到的:

^ Illuminate\Http\UploadedFile {#1168 ▼
  -test: false
  -originalName: "gary-bendig-6GMq7AGxNbE-unsplash.jpg"
  -mimeType: "application/octet-stream"
  -error: 1
  #hashName: null
  path: ""
  filename: ""
  basename: ""
  pathname: ""
  extension: ""
  realPath: "/app/public"
  aTime: 1970-01-01 00:00:00
  mTime: 1970-01-01 00:00:00
  cTime: 1970-01-01 00:00:00
  inode: false
  size: false
  perms: 00
  owner: false
  group: false
  type: false
  writable: false
  readable: false
  executable: false
  file: false
  dir: false
  link: false
}

我猜这是某种文件系统权限问题,但可以考虑。

【问题讨论】:

    标签: php laravel heroku


    【解决方案1】:

    试试这个解决方案 (.user.ini) - https://stackoverflow.com/a/28897926/7092969

    如果它不起作用:

    1. 让我们在根目录下创建nginx.conf 并添加以下内容:
    client_max_body_size 25M;
    
    location / {
        # try to serve file directly, fallback to rewrite
        try_files $uri @rewriteapp;
    }
    
    location @rewriteapp {
        # rewrite all to index.php
        rewrite ^(.*)$ /index.php/$1 last;
    }
    
    location ~ ^/index\.php(/|$) {
        try_files @heroku-fcgi @heroku-fcgi;
        # ensure that /index.php isn't accessible directly, but only through a rewrite
        internal;
    }
    
    
    1. Procfile 内容设置为:
    web: vendor/bin/heroku-php-nginx -C nginx.conf public/
    
    1. 重新部署 Heroku 应用程序

    【讨论】:

      【解决方案2】:

      事实证明,上传

      【讨论】:

        猜你喜欢
        • 2017-06-30
        • 2012-08-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多