I have a lot of video files archived in the AWS Glacier. Majority of them have ".mp4" format, How can I get an extension of a file stored in the archive?
I use php-aws-sdk and Laravel. I'm trying to remove that hardcoded ".mp4", It returns me a "stream" when I'm trying to get "$result->get('body')", I didn't see any fields with extension of the file in that object.
$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);
CodePudding user response:
you can use this
$extension = $file->getClientOriginalExtension();
$extension = pathinfo(storage_path('/uploads/my_image.jpg'), PATHINFO_EXTENSION);dd($extension);
//Where $file is an instance of Illuminate\Http\UploadFile
$extension = $file->getClientOriginalExtension();
CodePudding user response:
It is opposite, I mean how to get an extension when I'm going to download a file from glacier, I don't have that file on my server yet.
What glacier returns me is:
GuzzleHttp\Psr7\Stream^ {#1155 -stream: stream resource {@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: [] }
I can use ->get('body') of that stream object and save it to the file. But how to find our what is the extension there, of a file I'm going to create?
$fp = fopen('/tmp/' . $archive_name . '.mp4', "w");
fwrite($fp, $result->get('body'));
fclose($fp);