首页 > 解决方案 > 从 AWS Glacier 下载文件时如何找到文件的扩展名?

问题描述

我在 AWS Glacier 中存档了很多视频文件。它们中的大多数具有“.mp4”格式,如何获取存储在存档中的文件的扩展名?

我使用 php-aws-sdk 和 Laravel。我正在尝试删除硬编码的“.mp4”,当我尝试获取“$result->get('body')”时它返回一个“流”,我没有看到任何扩展名为的字段该对象中的文件。

    $result = $this->client->getJobOutput([
        'accountId' => config('aws.account_id'),
        'jobId' => $job_id,
        'vaultName' => config('aws.vault_name'),
    ]);

    $video_file_name = '/tmp/' . $archive_name . '.mp4'; 

    $video_file_path = public_path($video_file_name);
    $fp = fopen($video_file_path, "w");
    fwrite($fp, $video_source_stream);
    fclose($fp);

标签: phplaravelamazon-web-servicessdkamazon-glacier

解决方案


相反,我的意思是当我要从冰川下载文件时如何获得扩展名,我的服务器上还没有那个文件。

冰川返回给我的是:

GuzzleHttp\Psr7\Stream^ {#1155 -stream: 流资源 {@722 wrapper_type: "PHP" stream_type: "TEMP" mode: "w+b" unread_bytes: 0 seekable: true uri: "php://temp" options : [] } -size: null -seekable: true -readable: true -writable: true -uri: "php://temp" -customMetadata: [] }

我可以使用该流对象的 ->get('body') 并将其保存到文件中。但是如何找到我们要创建的文件的扩展名是什么?

$fp = fopen('/tmp/' . $archive_name . '.mp4', "w");
fwrite($fp, $result->get('body'));
fclose($fp);

推荐阅读