-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransferUitlity should have ACL option for uploading file (needs 2 request to upload a public-read file) #63
Comments
+1 |
The PutObjectRequest has the ACL Option (withCannedAcl) but the TransferUtility and its UploadTask does not have an option to set it, so it will be null. =Z |
Thanks for the request guys, I'll keep this issue open and I've added this to our feature request list. If others feel like this is a feature they want please +1 so we can adjust our priorities accordingly! That being said AWS in general recommends using IAM policies or bucket policies see http://blogs.aws.amazon.com/security/post/TxPOJBY6FE360K/IAM-policies-and-Bucket-Policies-and-ACLs-Oh-My-Controlling-Access-to-S3-Resourc that being said, I understand there are situations where having an ACL might be easier. |
+1 2015-10-06 14:29 GMT-05:00 wdane [email protected]:
Angel Romero Salazar |
+1 |
+1 |
Thanks for the so fast reply, wdane! |
+1 |
+1 |
+1 |
+1 |
So till this feature request is implemented, Is there way around to this situation ? |
A work around is that you can apply bucket policy to the bucket you upload objects. See Bucket Policy Examples. The following bucket policy grants read only permission to objects under {
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::foo/bar/*","arn:aws:s3:::foo/foobar/*"]
}
]
} See my original answer on StackOverflow How to specify public-read policy on a complete bucket in aws?. |
The problem with this solution is that you change the whole bucket policy when you just want to change one object ACL. And if you want to change only one file you have to do an extra call to set ACL while it could be already set on the object in the upload. My solution was not to use TransferUtility, which is sad because it has a good implementation on a separate service, etc, but i've used the PutObjectRequest inside an AsyncTask. Here is the code: private class UploadFileTask extends AsyncTask<Void, Long, Exception> {
private FileUploadCallback callback;
private AWSCredentials credentialsProvider;
private String fileUrl;
private boolean publicRead;
private String bucket;
private FileUploader uploaderInstance; //used to store client for reuse in same Uploader Instance
private AmazonS3Client s3Client = null;
private boolean cancelled = false;
private long totalSize = 0;
private long totalTransferred = 0;
public UploadFileTask(AmazonS3Client s3Client, String fileUrl, String bucket,boolean publicRead, FileUploadCallback callback, AWSCredentials credentialsProvider, FileUploader instanceReference)
{
this.s3Client = s3Client;
this.fileUrl = fileUrl;
this.bucket = bucket;
this.publicRead = publicRead;
this.credentialsProvider = credentialsProvider;
this.callback = callback;
this.uploaderInstance = instanceReference;
}
protected Exception doInBackground(Void... urls) {
//Instantiate and store reference on uploader Instance
if(s3Client == null) {
s3Client = new AmazonS3Client(credentialProvider);
s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
s3Client.setRegion(defaultRegion);
uploaderInstance.setS3Client(s3Client);
}
File f = new File(fileUrl);
try {
totalSize = f.length();
}
catch (Exception e)
{
return e;
}
PutObjectRequest por = new PutObjectRequest(this.bucket,f.getName(),f);
if(this.publicRead)
{
por.setCannedAcl(CannedAccessControlList.PublicRead);
}
por.setGeneralProgressListener(new ProgressListener() {
@Override
public void progressChanged(ProgressEvent progressEvent) {
//Log.i("PROGRESS",progressEvent.getEventCode() + " - " + progressEvent.getBytesTransferred());
if(progressEvent.getEventCode() == 0)
{
totalTransferred += progressEvent.getBytesTransferred();
publishProgress(totalTransferred);
}
else if(progressEvent.getEventCode() == ProgressEvent.CANCELED_EVENT_CODE)
{
cancelled = true;
}
}
});
try {
s3Client.putObject(por);
//Notify success
return null;
}
catch (Exception e)
{
//Notify error
return e;
}
}
protected void onProgressUpdate(Long... progress) {
if(callback!=null)
{
callback.onUploadProgressChanged(progress[0].longValue(),totalSize);
}
}
protected void onPostExecute(Exception exception) {
if(callback!=null) {
if (exception == null) {
if(!cancelled) {
callback.onUploadSuccess();
}
else
{
callback.onUploadCanceled();
}
}
else
{
callback.onUploadError(exception);
}
}
}
} |
@fernando-closs-clansoft that should do the job :). What I proposed is an alternate solution and is applicable most of the time. There are a few benefits.
Just my two cents. Back to the original topic, I'll leave this issue open as feature request. |
@fosterzhang I completely agree with you. In my case there was no way to have this directory structure due to retro compatibility with an existing iOs app. But this is a good solution until we have the ACL option in the feature. =) |
+1 |
+1, would rather not have to use 2 calls if using TransferUtility. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
+1!!!!! |
|
+1 |
2 similar comments
+1 |
+1 |
+1 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
👍 |
+1 |
+1 , been months and still waiting. |
+1 |
please please add it |
Hi all, this feature has been added to v2.2.15. See release notes. |
thanks @fosterzhang, please close this |
+1, would rather not have to use 2 calls if using TransferUtility. |
Is it implemented? Why a feature? It is a bug! |
The transfer utility is fantastic, but there is too much limitation on changing the putobjectrequest, it is only possible to set the metadata. Something like the TransferUtilityUploadRequest (as in .Net sdk) should be also available in Android.
To upload a public-read file using it, i need to handle the successful upload, then set the ACL, then finally notify the success on uploading the file. One unnecessary extra request, but i wouldn't like to lose all the benefits of the TransferService and Transfer Utility.
Thanks for your attention.
The text was updated successfully, but these errors were encountered: