2013-03-21 108 views
3

我正在研究一個需要將圖像上傳到S3的應用程序。現在我這樣做:通過CloudFront將內容上傳到S3

S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:nameOfThePicture inBucket:nameOfTheBucket]; 
    por.contentType = @"image/jpg"; 
    por.data  = imageData; 

    // Put the image data into the specified s3 bucket and object. 
    S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por]; 
    por.delegate = self; 

將圖像直接上傳到S3太慢,我配置了CloudFront服務。 現在,我想通過CloudFront將圖像上傳到S3中的原始存儲分區。有可能做到這一點?如果是的話,我該怎麼做?

真的感謝,

維克多

回答

4

號CloudFront的是一個單向的事 - 你可以通過CloudFront的檢索S3對象,但你無法通過CloudFront的上傳對象S3。

+0

好的。謝謝回答。 – VICTORGS3 2013-03-21 22:45:21

+1

更新:2013年10月更新。CloudFront現在將HTTP PUT和POST命令(等等)傳遞到原點。但AFAICT在任何SDK中都不能通過S3 API工作。 – 2013-10-21 17:20:42

+0

我想要讓所有S3授權標題正確通過可能會有問題。 – duskwuff 2013-10-21 21:21:53

0

我在我的項目中有相同的要求。雖然我自己無法弄清楚所有的事情,但是我遇到了一個鏈接。

http://raamdev.com/2008/using-curl-to-upload-files-via-post-to-amazon-s3/

我試圖模仿與PHP捲曲相同,但不知何故,我看到密鑰已上載,而不是圖像文件。可能這個代碼會爲你提供指針,如果有人能夠在下面的腳本中找出問題,那對我和任何想要實現這一點的人都會有很大的幫助。

$url = 'http://xxxxxxxxxxx.cloudfront.net/'; // cloudfront distribution url. 

$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 

//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array("key"=>$_REQUEST['key'],"file"=>$_FILES['file']['tmp_name'])); 


//curl_setopt($ch, CURLOPT_POSTFIELDS, array("key"=>$_FILES['file']['tmp_name'])); 
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch); 

if (false == $result) { 
    echo "Error while loading page: ", curl_error($ch), "\n"; 
} 
curl_close($ch); 
var_dump($result); 
相關問題