I'm using the aws sample code to upload files to the S3, but when they get uploaded they come with no access for anyone, even with the bucket made Public for everyone, the only way to read it is to manually set the files on the S3 console to give public access.
MyService:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null && intent.getStringExtra(INTENT_KEY_NAME) != null) {
final String key = intent.getStringExtra(INTENT_KEY_NAME);
final File file = (File) intent.getSerializableExtra(INTENT_FILE);
final String transferOperation = intent.getStringExtra(INTENT_TRANSFER_OPERATION);
TransferObserver transferObserver;
switch (transferOperation) {
case TRANSFER_OPERATION_DOWNLOAD:
Log.d(TAG, "Downloading " + key);
transferObserver = transferUtility.download("aws-MYBUCKET", key, file);
transferObserver.setTransferListener(new DownloadListener());
break;
case TRANSFER_OPERATION_UPLOAD:
Log.d(TAG, "Uploading " + key);
transferObserver = transferUtility.upload("aws-MYBUCKET", key, file);
transferObserver.setTransferListener(new UploadListener());
break;
}
return START_STICKY;
} else return START_NOT_STICKY;
In the Amazon S3 console, choose the bucket where you want to upload an object, choose Upload, and then choose Add Files. In the file selection dialog box, find the file that you want to upload, choose it, choose Open, and then choose Start Upload. You can watch the progress of the upload in the Transfer pane.
S3 Block Public Access provides controls across an entire AWS Account or at the individual S3 bucket level to ensure that objects never have public access, now and in the future. Public access is granted to buckets and objects through access control lists (ACLs), bucket policies, or both.
You should create a Bucket Policy. This can grant public access for the whole bucket, or a portion of the bucket.
From Bucket Policy Examples - Amazon Simple Storage Service:
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::examplebucket/*"]
}
]
}
This is preferable to granting access on individual objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With