我正在尝试在 php 中创建一个存档和检索系统。当用户点击存档按钮时,特定文件将从标准存储移动到冰川存储,当点击恢复按钮时,冰川存储中的文件将检索到标准存储。
使用 AWS php SDK 3.0 api,我已成功将文件移动到 glacier vault 并为检索启动了存档检索作业,我在 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 操作文档),getJobOutput 函数的 saveAs 属性是指定应该下载操作内容的位置。可以是文件的路径、fopen 返回的资源或 Guzzle\Http\EntityBodyInterface 对象。因为我也在 s3 中给出了文件的路径。会有什么问题。非常感谢任何帮助。提前致谢。
这是响应 $result 中包含的结果,与文档中提到的完全相同
Aws\Result 对象 ( [data:Aws\Result:private] => 数组 ( [body] => GuzzleHttp\Psr7\Stream 对象 ( [stream:GuzzleHttp\Psr7\Stream:private] => 资源 id #25 [大小: 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] => 数组 ()) [校验和] => c176c1843fd0c0fc662lh9bb8de916540e6f9dpk9b22020bbb8388jk6f81d01c2 [2状态] => contentRange] => [acceptRanges] => bytes [contentType] => application/octet-stream [archiveDescription] => 文件名是 children-wide.jpg [@metadata] => Array ([statusCode] => 200 [effectiveUri] =>https://glacier.region-name.amazonaws.com/-/vaults/vaultname/jobs/gFdjAl4xhTAVEnmffgfg-Ao3-xmmjghfmqkCLOR1m34gHLQpMd0a3WKCiRRrItv2bklawwZnq9KeIch3LKs8suZoJwk2_/output [headers] => Array ( [x-amzn-requestid] => NzAiVAfrMQbpSjj-2228iiKWK_VteDwNyFTUR7Kyu0duno [x -amz-sha256-tree-hash] => c176c1843khfullc662f09bb8de916540e6f9dcc9b22020bbb8388de6f81d1c2 [accept-ranges] => bytes [x-amz-archive-description] => 文件名是 children-wide.jpg [content-type] => application/octet-流 [内容长度] => 1452770 [日期] => 格林威治标准时间 2017 年 1 月 31 日星期二 03:34:26 [连接] => 关闭) [transferStats] => 数组 ([http] => 数组 ([0] = > 数组 ( ) ) ) ) )