2013-03-21 116 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);