外部サーバーからAPIで取得した(AWS S3)画像を自分のサーバーに置きたいのですが下記のエラーでできないです、
教えてくださいませ!!
外部:AWS S3
自分:AWS Linux
言語:Laravel5
エラー:
(1/1) ErrorException file_get_contents(<?xml version="1.0" encoding="UTF-8"?> <Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>xxxxxxxxxxxxx</AWSAccessKeyId><StringToSign>GET Thu, 01 Feb 2018 08:24:10 +0000 /xxxxxxxxxx-bucket/</StringToSign><SignatureProvided>RwCVSdQpjZixoSICSgNGfMAxHHA=</SignatureProvided><StringToSignBytes>47 45 54 0a 0a 0a 54 68 75 2c 20 30 31 20 46 65 62 20 32 30 31 38 20 30 38 3a 32 34 3a 31 30 20 2b 30 30 30 30 0a 2f 6e 65 6f 2d 63 61 72 65 65 72 2d 73 74 61 67 69 6e 67 2d 62 75 63 6b 65 74 2f</StringToSignBytes><RequestId>194FCB18F00D2897</RequestId><HostId>7b9r8HF2HNqoX0ef9l6uaYQDR6w+m+1PCaSHqA9mX8Z3OogVsjXDVkXnJ6RXc8tNM9WXj0bZFgw=</HostId></Error>): failed to open stream: No such file or directory
ソースコード:
<?php // ----- Signature ----- // HTTP-Verb $httpVerb = 'GET' . "\n"; // Content-MD5 $contentMd5 = "\n"; // Content-Type $contentType = "image/jpeg \n"; // Date $datetime = new DateTime('now', new DateTimeZone('UTC')); $date = $datetime->format(DateTime::RFC1123) . "\n"; echo $date; // CanonicalizedAmzHeaders $canonicalizedAmzHeaders = ''; // CanonicalizedResource $canonicalizedResource = '/'; // StringToSign $stringToSign = $httpVerb . $contentMd5 . $contentType . $date . $canonicalizedAmzHeaders . $canonicalizedResource; // Signature $accessKeyId='xxxxxxxxxxxx'; $secretAccessKey=''; $hash = hash_hmac('sha1', $stringToSign, $secretAccessKey, true); $signature = base64_encode($hash); $authorization = 'AWS' . ' ' . $accessKeyId . ':' . $signature; $ch = curl_init('https://xxxxxxx-bucket.s3-ap-northeast-1.amazonaws.com'); $headers = array( 'Authorization: AWS '.$accessKeyId.':'.$signature, 'Date: ' . $date, ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $body = curl_exec($ch); curl_close($ch); var_dump($body); ?>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。