【问题标题】:Keep on recieving error: AWS HTTP error: cURL error 6: when trying to upload file继续收到错误:AWS HTTP 错误:cURL 错误 6:尝试上传文件时
【发布时间】:2020-01-31 03:39:58
【问题描述】:

每次我尝试使用 sdk 将文件上传到我的 s3 存储桶时,我都会不断收到错误消息(AWS HTTP 错误:cURL 错误 6)。我不知道为什么会发生这种情况,也不知道如何解决它。还有什么我需要添加到我的代码或指定的吗?问题只是存储桶还是我创建的用户(IAM)。我不需要明确的答案,我只需要一些可以缩小我需要寻找错误原因的区域的东西。我很乐意感谢任何回应。谢谢。

这是我的代码:

<?php
require 'vendor/autoload.php';

use Aws\S3\S3Client;

// Instantiate an Amazon S3 client.
$s3 = new S3Client([
    'version' => 'latest',
    'region'  => 'US-West', 
    'credentials' => [
        'key'    => 'garbage',
        'secret' => 'garbage'
    ]
]);


$bucketName = 'garbage';
$file_Path = __DIR__ . '/my-image.png';
$key = basename($file_Path);

// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
    $result = $s3->putObject([
        'Bucket' => $bucketName,
        'Key'    => 'videouploads/' . $key,
        'Body'   => fopen($file_Path, 'r'),
        'ACL'    => 'public-read',
    ]);
    echo $result->get('ObjectURL');
} catch (Aws\S3\Exception\S3Exception $e) {
    echo "There was an error uploading the file.\n";
    echo $e->getMessage();
}


?>

【问题讨论】:

标签: php amazon-web-services amazon-s3 sdk


【解决方案1】:

该错误对应于could not resolve host 错误。见CURLE_COULDNT_RESOLVE_HOST (6) https://curl.haxx.se/libcurl/c/libcurl-errors.html。这表明该库无法到达代码引用的 S3 端点。

检查代码,似乎区域定义不正确。您已将区域定义为'region' =&gt; 'US-West'。没有这样的地区。使用错误的区域名称可能会解释找不到主机错误。它试图访问一个不存在的区域中的主机名,并生成错误 6。

将该区域值替换为us-west-1us-west-2,然后重试。

【讨论】:

    猜你喜欢
    • 2018-07-19
    • 2020-03-26
    • 2021-08-09
    • 2013-06-27
    • 2017-02-20
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    相关资源
    最近更新 更多