【问题标题】:Upload Large size file to Amazon S3 fails on server在服务器上将大型文件上传到 Amazon S3 失败
【发布时间】:2019-08-07 23:04:35
【问题描述】:

我在尝试使用 PHP SDK 将 4MB 的文件上传到 S3 存储桶时遇到问题。这在我的流浪环境中运行良好。但是当我在 EC2 生产服务器上尝试时,当我要上传 2MB 大小的文件时,它会给出以下错误。但是可以毫无问题地上传小文件。有人可以帮我解决这个问题吗?

我在两种环境中都使用 nginx。

    $s3 = \App::make('aws')->createClient('s3');
    $name= time() . $file->getClientOriginalName();
    $resp = $s3->putObject(array(
        'Bucket' => 'xxxxxx',
        'Key' => $folder.'/' . $name,
        'ACL' => 'public-read',
        'Body' => new Stream(fopen(realpath($file->getPathName()), 'r'))
    ));

    if ($resp['@metadata']['statusCode'] == 200) {
        return [
            "file_path"=>$resp['ObjectURL'],
            "s3_key"=>$folder.'/' . $name
        ];
    }else{
        return false;
    }

在“https://xxxxxxx.amazonaws.com/documents/1564900266slides.zip”上执行“PutObject”时出错; AWS HTTP 错误:客户端错误:PUT https://xxxxxxx.amazonaws.com/documents/1564900266slides.zip 导致 400 Bad Request 响应:RequestTimeoutYour 与服务器的套接字连接 wa(截断...) RequestTimeout(客户端):您与服务器的套接字连接未在其中读取或写入超时时间。空闲连接将被关闭。 - RequestTimeout 您与服务器的套接字连接在超时期限内没有被读取或写入。

【问题讨论】:

    标签: php amazon-web-services nginx laravel-5 amazon-s3


    【解决方案1】:

    检查 nginx 是否有类似 client_max_body_size 20M; 的参数集,以允许文件上传最大 20 MB。 至于 PHP,你可以检查 php.ini upload_max_filesize = 20M 以匹配 nginx 配置。

    一旦您设置了这些参数,您必须使用 sudo nginx -t 检查 nginx 配置并使用 sudo service nginx reload 重新加载配置以应用新设置。

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      • 2020-06-04
      相关资源
      最近更新 更多