2016-08-03 79 views

回答

3

要設置S3對象公衆使用Android SDK就可以把桶政策到你的水桶,如:

{ 
    "Version": "2012-10-17", 
    "Id": "Policy20160803001", 
    "Statement": [ 
     { 
      "Sid": "Stmt20160803001", 
      "Effect": "Allow", 
      "Principal": "*", 
      "Action": "s3:GetObject", 
      "Resource": "arn:aws:s3:::[BUCKET_NAME]/*" 
     } 
    ] 
} 

有了這樣的政策,在給定的桶中的所有對象都將是公開的。

或者,如果你不想讓所有的桶對象公開,只是用你的Android SDK上傳的,你可以使用:

AmazonS3 s3 = new AmazonS3Client(credentials); 
s3.setObjectAcl(Constants.S3_BUCKET, key,CannedAccessControlList.PublicRead); 

final TransferUtility transferUtility = new TransferUtility(s3, getActivity()); 

TransferObserver observer = transferUtility.upload(
          Constants.S3_BUCKET, // S3 BUCKET TO UPLOAD FILE TO 
          key,     // NAME OF THE FILE IN THE S3 BUCKET 
          file     // FILE THAT WILL BE UPLOADED 
        ); 

一些相關的問題:

相關問題