正在测试使用CloudFlare R2,目前遇到几个问题:
1、使用flysystem-aws-s3-v3,上传文件出现错误:
`501 Not Implemented` response: <Error><Code>NotImplemented</Code><Message>Header 'x-amz-acl' with value 'public-read' not implement (truncated...) NotImplemented (server): Header 'x-amz-acl' with value 'public-read' not implemented - <Error><Code>NotImplemented</Code><Message>Header 'x-amz-acl' with value 'public-read' not implemented</Message></Error>
或者新版本提示:
TypeError: fclose(): supplied resource is not a valid stream resource in src/XF/Util/File.php at line 188
这是由于当前R2不支持Public Access,所以ACL只允许使用private
修改办法:
找到文件:AwsS3Adapter.php,查找:
'ACL' => $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private',
替代为:
'ACL' => 'private',
查找:
$options['ACL'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private';
替代为:
$options['ACL'] = 'private';
即可以正常使用R2来存储上传文件
2、上传较小的文件时正常,但是当上传较大的文件时,总是会中断,IP链接显示为中断,系统错误提示为:
RuntimeException: Unable to copy file /tmp/filesname to internal-data...
这是由于当AWS S3 API的PUT Object时,并发连接默认值与R2允许的并发值multipart restriction不一样。R2的默认值为2,但是API的Put Object的concurrency默认值为3,需要修改:
找到文件:aws-sdk-php/src/S3/ObjectUploader.php
查找:
'concurrency' => 3,
修改为:
'concurrency' => 2,
上传大文件时即可正常