具有权限的 URI 的路径必须以斜杠“/”开头或为空 DigitalOcean Spaces AWS S3 SDK PHP

问题描述

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);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...