简体   繁体   English

从 Laravel 5.4 上传到 S3 存储桶时出错

[英]Error uploading from Laravel 5.4 to S3 bucket

[I run the script from localhost] [我从本地主机运行脚本]

I'm trying to upload files using Laravel 5.4 to AWS S3 bucket but I get this error:我正在尝试使用 Laravel 5.4 将文件上传到 AWS S3 存储桶,但出现此错误:

Error executing "PutObject" on "https://bucket_name.s3.amazonaws.com/1520719994357906.png"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

In filesystems.php:在 filesystems.php 中:

's3' => [
        'driver' => 's3',
        'key' => 'KRY_HERE',
        'secret' => 'SECRET_HERE',
        'region' => 'us-east-1',
        'bucket' => 'bucket_name', //has global access to read files
    ],

In the controller:在控制器中:

Storage::disk('s3')->put($imageName, file_get_contents(public_path('galleries/').$imageName));

How to solve this?如何解决这个问题? If I upload the app to EC2 instance does it require SSL installed to upload files to S3 bucket?如果我将应用程序上传到 EC2 实例,是否需要安装 SSL 才能将文件上传到 S3 存储桶? Thanks in advance.提前致谢。

Uploading from server worked fine no need to install SSL it just doesn't work from localhost.从服务器上传工作正常,不需要安装 SSL,它只是不能从本地主机工作。

it just doesn't work from localhost,if you want to do working it on localhost you have to do some changes in vendor directory.(For your local use only)它只是在本地主机上不起作用,如果你想在本地主机上工作,你必须在供应商目录中做一些更改。(仅供本地使用)

vendor/guzzle/src/handler/CurlFactory.php供应商/guzzle/src/handler/CurlFactory.php

Near around line no 350.Comment this two line and add new two line,otherwise replace this two line.(as you wish)在第 350 行附近。评论这两行并添加新的两行,否则替换这两行。(如你所愿)

  if ($options['verify'] === false) {
                    unset($conf[\CURLOPT_CAINFO]);
                    $conf[\CURLOPT_SSL_VERIFYHOST] = 0;
                    $conf[\CURLOPT_SSL_VERIFYPEER] = false;
                } else {
               /* $conf[\CURLOPT_SSL_VERIFYHOST] = 2;
                  $conf[\CURLOPT_SSL_VERIFYPEER] = true;*/ //Comment this two line
                  $conf[\CURLOPT_SSL_VERIFYHOST] = 0;
                  $conf[\CURLOPT_SSL_VERIFYPEER] = false;
}  

Now it's work fine.现在它工作正常。

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

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