【问题标题】:The path of a URI with an authority must start with a slash "/" or be empty. DigitalOcean Spaces AWS S3 SDK PHP具有权限的 URI 的路径必须以斜杠“/”开头或为空。 DigitalOcean Spaces AWS S3 开发工具包 PHP
【发布时间】:2021-06-17 22:06:19
【问题描述】:
System error occurred

The path of a URI with an authority must start with a slash "/" or be empty.
Automagically fixing the URI by adding a leading slash to the path is 
deprecated since version 1.4 and will throw an exception instead.
line#755 file: /home/mySite/www/vendor/guzzlehttp/psr7/src/Uri.php

PHP version: 7.4.14

Error executing "PutObject" on "//mySite.nyc3.digitaloceanspaces.com/mySite.nyc3.digitaloceanspaces.com"; 
AWS HTTP error: 
Server error: 
PUT http://mySite.nyc3.digitaloceanspaces.com/mySite.nyc3.digitaloceanspaces.com
resulted in a `501 Not Implemented` response:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NotImplemented</Code>
<RequestId>tx00000000000000c12754f-0060564e57-96 (truncated...)
 NotImplemented (server): 
<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>NotImplemented</Code>
  <RequestId>tx00000000000000c12754f-0060564e57-9617be5-nyc3c</RequestId
  <HostId>9617be5-nyc3c-nyc3-zg03</HostId>
</Error>"

我不完全理解这个错误,我尝试过更改请求头,我不知道还能尝试什么,我现在是空白的。我还认为这是标题中的问题。目前我的标头请求如下所示:

:authority: mySite.com
:method: POST
:path: /request.ajax.php
:scheme: https

我也会留下各自的php代码:

function __construct($key, $secret_key, $space)
{
       $this->space = $space;

       try {
            $this->client = new \Aws\S3\S3Client([
                'version'  => 'latest',
                'region'   => 'us-east-1',
                'endpoint' => 'nyc3.digitaloceanspaces.com',
                'credentials' => [
                    'key'    => $key,
                    'secret' => $secret_key
                ],
            ]);
        } catch (\Exception $e) {
            return $e->getMessage();
        }
}

public _upload($path, $resource, $ctype)
{
        try {
            $this->client->putObject(array(
                'Bucket' => $this->space,
                'Key'    => $path,
                'Body'   => $resource,
                'ACL'    => 'public-read',
                'ContentType' => $ctype
            ));
        } catch (\Exception $e) {
            return $e->getMessage();
        }

        return array("status" => "Success.");
}

我管理上传文件的部分:

$path = "test/".basename($_FILES['file']['name']);
$ctype = mime_content_type($_FILES['file']['tmp_name']);
$stream = fopen($_FILES['file']['tmp_name'], 'r+');
$out = $xspaces->_upload($path, $stream, $ctype);
fclose($stream);

【问题讨论】:

  • 传递给初始化$xspace对象的$space值是什么?
  • 我使用的值是一个文本字符串,它是存储内容的数字海洋空间或桶。
  • 我认为它试图告诉您$path 需要以斜杠开头...? docs.aws.amazon.com/aws-sdk-php/v3/api/…
  • 你的意思是这样的吗? "/test/" . basename($_FILES['file']['name']);我最近尝试过,但我仍然遇到同样的错误,我已经在 localhost 中测试了我的代码(没有斜杠)并按预期工作,但是当我尝试在我的服务器中使用它时它不工作

标签: php amazon-web-services digital-ocean-spaces


【解决方案1】:

在关注this article 之后,我也有同样的问题,只需更改您的 .env 并将协议添加到 endpoint

没有协议我得到同样的错误(错误)
DO_SPACES_ENDPOINT=sgp1.digitaloceanspaces.com

修复只是将协议添加到 do_space (正确)
DO_SPACES_ENDPOINT=https://sgp1.digitaloceanspaces.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 2022-11-02
    • 2020-04-26
    相关资源
    最近更新 更多