我正在尝试在php中创建存档和检索系统。当用户单击归档按钮时,特定文件将从标准存储移动到冰川存储,并且当点击冰川存储中的恢复按钮文件时将检索到标准存储。
使用AWS php SDK 3.0 api我已经成功地将文件移动到冰川保险库并且用于检索存档检索作业已启动并且我在3-5小时后获得了作业ID并且在5小时后使用该作业ID我尝试了getJobOutput功能。我得到的响应与api文档中提到的相同,但我没有在s3存储桶中获取已恢复的文件。
以下是我上传到冰川并从冰川恢复的代码
public function archiveAndRestore() {
$this->s3Client = new S3Client(Configure::read('AWScredentials'));
$this->glacier = GlacierClient::factory(Configure::read('AWScredentials'));
// Upload to glacier
$this->s3Client->registerStreamWrapper();
$context = stream_context_create([
's3' => ['seekable' => true]
]);
$result = $this->glacier->uploadArchive(array(
'vaultName' => 'archiveTest',
'archiveDescription' => 'File Name is archiveTest.txt ',
'body' => fopen('s3://storage-bucket/Videos/archiveTest.txt', 'r', false, $context),
));
$archiveid = $result->get('archiveId');
$jobId = $this->glacier->initiateJob([
'accountId' => '-',
'vaultName' => 'archiveTest',
'jobParameters' => [
'Type' => 'archive-retrieval',
'ArchiveId' => 'ORgyyyqsKwoopp110EvFoyqj3G-csmOKLyy3IJnWF9Dpd8BJfwerEhg241nxHf6y6kNUUyhUHOaY4y8QvWBGESmAopa80f6GZ9C05tyyKANhY-qfBUB6YkfTABg',
],
]);
$this->s3Client->registerStreamWrapper();
$context = stream_context_create([
's3' => ['seekable' => true]
]);
$stream = fopen('s3://storage-bucket/RetrivedFiles/test1.txt', 'w');
$result = $this->glacier->getJobOutput([
'accountId' => '-',
'jobId' => '2dddfffffff9SwZIOPWxcB7TLm_3apNx--2rIiD7SgjOJjjkrerrcN1YCtivh_zsmpLyczY4br-bhyyX0Ev5B7e6-D1',
'vaultName' => 'archiveTest',
'saveAs' => $stream,
]);
fclose($stream);
}
根据文档(aws GetJobOutput operation documentation),getJobOutput函数的saveAs属性是指定应该下载操作内容的位置。可以是文件的路径,fopen返回的资源,或Guzzle \ Http \ EntityBodyInterface对象。因为我也在s3中给出了文件的路径。会是什么问题。任何帮助都非常感谢。提前谢谢。
这是响应$ result中包含的结果,与文档
中提到的完全相同Aws \ Result Object([data:Aws \ Result:private] => Array([body] => GuzzleHttp \ Psr7 \ Stream Object([stream:GuzzleHttp \ Psr7 \ Stream:private] =>资源id#25 [size:GuzzleHttp \ Psr7 \ Stream:private] => [seekable:GuzzleHttp \ Psr7 \ Stream:private] => 1 [可读:GuzzleHttp \ Psr7 \ Stream:private] => 1 [可写: GuzzleHttp \ Psr7 \ Stream:private] => 1 [uri:GuzzleHttp \ Psr7 \ Stream:private] => php:// temp [customMetadata:GuzzleHttp \ Psr7 \ Stream:private] => Array())[ checksum] => c176c1843fd0c0fc662lh9bb8de916540e6f9dpk9b22020bbb8388jk6f81d1c2 [status] => 200 [contentRange] => [acceptRanges] => bytes [contentType] => application / octet-stream [archiveDescription] =>文件名是全儿童的。 jpg [@metadata] =>数组([statusCode] => 200 [effectiveUri] => https://glacier.region-name.amazonaws.com/-/vaults/vaultname/jobs/gFdjAl4xhTAVEnmffgfg-Ao3-xmmjghfmqkCLOR1m34gHLQpMd0a3WKCiRRrItv2bklawwZnq9KeIch3LKs8suZoJwk2_/output [headers] =>数组([x-amzn-requestid] => NzAiVAfrMQbpSjj-2228iiKWK_VteDwNyFTUR7Kyu0duno [ x-amz-sha256-tree-hash] => c176c1843khfullc662f09bb8de916540e6f9dcc9b22020bbb8388de6f81d 1c2 [accept-ranges] => bytes [x-amz-archive-description] =>文件名是children-wide.jpg [content-type] => application / octet-stream [content-length] => 1452770 [日期] => 2017年1月31日星期二03:34:26 GMT [连接] =>关闭)[transferStats] =>数组([http] =>数组([0] =>数组())))))
答案 0 :(得分:0)
当您从Glacier恢复文件时,它将不再将Standard作为存储类。它仍会显示冰川。确定文件是否来自Glacier,
改为使用GetObject,并查看结果的恢复值。并将Range设置为“bytes = 0-0”以跳过检索文件本身的内容。并确保陷阱异常
如果对象位于Glacier中且未恢复,则AWS将抛出InvalidObjectStateError,如果未捕获到错误,脚本将会死亡。
您将看到该项目已恢复。
[“恢复”] => string(68)“ongoing-request =”false“,expiry-date =”Thu, 2017年10月12日00:00:00 GMT“”
如果Item仍然在Glacier中,这就是你将得到的
致命错误:未捕获异常'Aws \ S3 \ Exception \ S3Exception' 消息'执行“GetObject”时出错 “OBJ PATH”; AWS HTTP错误:客户端错误:
GET OBJ PATH
导致403 Forbidden
响应: InvalidObjectStateThe 操作对于(截断的...)InvalidObjectState无效 (客户端):该操作对于对象的存储类无效 - InvalidObjectState该操作对于对象的存储无效 class879A42BDC3939282VjgBNmLxhqesAaOnnUKkIahdr9OlUnTPASmjh8zZNVzLeYEDz + QooqoFjyaeoyXGeAa / IPxTBrA =” GuzzleHttp \ Exception \ ClientException:客户端错误:`GET OBJ PATH 在 C:\的Inetpub \ wwwroot的\ cruisecheap.com \ php_includes \的SDK \ AWS \厂商\ AWS \ AWS-SDK-PHP中\ SRC \ WrappedHttpHandler.php 在第192行
我希望这可以帮助你和其他有同样问题的人。