お世話になっております。
PHPでS3からファイルをダウンロードするための署名付きURLを生成しているのですが、URLが長すぎる(約4,000文字前後)ためか、InternetExplorerでアクセスすると、エラーになってしまいます。
ちなみに、FirefoxやGoogleChromeで開けることは確認できました。
何かよい対処法はないでしょうか。
もしくは、そもそもこの方法で作成するのはよくないのでしょうか。
個人的にはInternetExplorerへの対応は打ち切りたいのですが、そうもいかない事情があるので、なんとかならないかと考えています。
ちなみに、S3のサービスとして、Wasabiを利用しています。
PHPのソースコードは、下記の通りです。
なお、アクセスキーやシークレットキーは省略しており、バケット名は仮の名前のものとなっています。
<?php
// constants
const wasabi_access_key = <Wasabiのアクセスキー>;
const wasabi_secret_key = <Wasabiのシークレットキー>;
const wasabi_download_role = <Wasabiで生成したダウンロード用のロール>;
const wasabi_download_session_name = 'downloadSession';
const wasabi_endpoint = 'https://s3.us-west-1.wasabisys.com';
const wasabi_sts_endpoint = 'https://sts.us-west-1.wasabisys.com';
const wasabi_bucket_name = 'test-bucket';
const wasabi_bucket_region = 'us-west-1';
define('s3_info', [
'endpoint' => wasabi_endpoint,
'region' => wasabi_bucket_region,
'version' => 'latest',
'credentials' => [
'key' => wasabi_access_key,
'secret' => wasabi_secret_key
],
]);
define('s3_sts_info', [
'endpoint' => wasabi_sts_endpoint,
'region' => wasabi_bucket_region,
'version' => 'latest',
'credentials' => [
'key' => wasabi_access_key,
'secret' => wasabi_secret_key
],
]);
// load modules
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
use Aws\S3\Exception\S3Exception;
use Aws\Credentials\CredentialProvider;
use Aws\Sts\StsClient;
use Aws\Credentials\AssumeRoleCredentialProvider;
use Aws\Sts\Exception\StsException;
require_once("aws.phar");
// variables
$real_filename = 'data/test.dat';
$download_filename = 'test.wav';
// create sts
try{
$stsClient = new StsClient(s3_sts_info);
$result = $stsClient->AssumeRole([
"RoleArn" => wasabi_download_role,
"RoleSessionName" => wasabi_download_session_name,
]);
}catch (StsException $e){
die("Failed assume role: ".$e->getMessage());
}
// result check
if (
isset($result["Credentials"]["AccessKeyId"])
&& isset($result["Credentials"]["SecretAccessKey"])
&& isset($result["Credentials"]["SessionToken"])
){
// create s3 client for download
try{
$dls3client = S3Client::factory([
"endpoint" => wasabi_endpoint,
"region" => wasabi_bucket_region,
"version" => 'latest',
"signature" => "v4",
"credentials" => [
"key" => $result["Credentials"]["AccessKeyId"],
"secret" => $result["Credentials"]["SecretAccessKey"],
"token" => $result["Credentials"]["SessionToken"]
],
]);
}catch (S3Exception $e){
die("Failed create s3 client for download: ".$e->getMessage());
}
// params for GetObject
$params = [
"Bucket" => wasabi_bucket_name,
"Key" => $real_filename,
"ResponseContentType" => "application/octet-stream",
"ResponseContentDisposition" => "attachment;filename*=UTF-8''".rawurlencode($download_filename)
];
// create prisigned URL
try{
$cmd = $dls3client->getCommand('GetObject', $params);
$request = $dls3client->createPresignedRequest($cmd, '+15 minutes');
$URL = (string)$request->getUri();
}catch (S3Exception $e){
die("Failed create prisigned URL: ".$e->getMessage());
}
}else{
exit;
}
// print link for download
?>
<a href="<?php echo $URL; ?>">Download file</a>
InternetExplorerのエラー内容は、下記の通りです。
このページを表示できません
• Web アドレス https://test-bucket.s3.us-west-1.wasabisys.com が正しいか確かめてください
以上、何かアドバイスをいただけますと幸いです。
よろしくお願いいたします。