お世話になっております。
この度AWS SDKを使用して画像のアップロードを行いたいと考えております。
そこで、aws.pharをダウンロードし、putObjectをしてみたのですが・・・
Error executing "PutObject" on "https://s3.ap_northeast_1.amazonaws.com/hoge/moge.txt";
となりPutできません。
エラーの内容
AWS HTTP error: cURL error 6: Couldn't resolve host 's3.ap_northeast_1.amazonaws.com' (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
を見る限り、ホストが見つからないとあります。
そこで、コンソールにログインしてテストファイルをアップロード、その後リンクをみると・・・ホストが
https://s3-ap_northeast_1.amazonaws.com/hoge/moge.txt
となっておりました。
プログラムでは「https://s3.ap_northeast_1...」に対し
実際のリンクは「https://s3-ap_northeast_1...」
これはどういうことなのでしょう@@;
そもそもプログラムの記述方法が間違っているのでしょうか。
何が間違っているかご教授頂ければ幸いです。宜しくお願い致します。
実際のプログラムは下記のとおりです。
PHP
1<?php if( ! defined('BASEPATH')) exit('No direct script access allowed'); 2 3require APPPATH."aws/aws.phar"; 4use Aws\S3\S3Client; 5 6class Awsci{ 7 8 function __construct(){ 9 $CI=& get_instance(); 10 $this->CI=$CI; 11 $this->CI->load->helper('url'); 12 13 global $s3; 14 15 } 16 17 public function putObject($name,$file){ 18 global $s3; 19 $s3=new S3Client([ 20 'region'=>'ap_northeast_1', 21 'version'=>'2006-03-01', 22 'credentials'=>[ 23 'key'=>'xxxxxxxxxxxxxxxxxxxxxxxxx', 24 'secret'=>'xxxxxxxxxxxxxxxxxxxxxxx', 25 ] 26 ]); 27 28 $res=$s3->putObject(array( 29 'Bucket'=>'hoge', 30 'Key'=>'moge.txt', 31 'ContentType'=>'text/plain', 32 'SourceFile'=>"moge.txt", 33 'StorageClass'=>'REDUCED_REDUNDANCY', 34 'ACL'=>'public-read', 35 )); 36 37 print_r($res); 38 } 39 40}//class 41?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。