aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
6.01k stars 1.22k forks source link

how do i find out if I have write permissions? #121

Closed simkimsia closed 11 years ago

simkimsia commented 11 years ago

given a bucket name, aws key, aws secret, and the key to the object, how can I tell if I have write permissions?

if I get a Aws\S3\Exception\NoSuchKeyException, then do I just check against the permissions of the bucket? if so, how?

Thank you

mtdowling commented 11 years ago

I'll ask the Amazon S3 team to get their feedback on this question. In the meantime, I believe that using a cors enabled bucket could be a good solution: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTOPTIONSobject.html.

simkimsia commented 11 years ago

Thank you, @mtdowling I will be looking at this a little later. I am now trying to integrate the file upload functions of my app with the aws sdk.

I noticed that the README of this repo calls for contributions to third party module integration.

My app uses CakePHP 2.4 and I am only integrating a few S3 functions in the SDK. Once I have a more stable module, how do I contribute to that?

mtdowling commented 11 years ago

What is your use case for needing to know up front if you have write permissions?

If you just want to check before attempting to write data, then I think it would actually be better and a more general purpose approach to just attempt to write the data and catch any exceptions that might be thrown from attempting to write. The reason I say this is because there are a lot of factors that determine whether or not you can write to an object:

  1. Check the object's ACL for a specific grantee's write permission. This requires that you have READ_ACP permissions, so the request to get an object's ACL could fail as well. This also requires that you can disambiguate the various grantee types (email, account ID etc) and that you have a grantee before checking the ACL.
  2. You could try the OPTIONs request approach, but this requires that a bucket has a cors configuration. Not all buckets have this, so attempting to download a bucket's cors configuration could fail as well.
  3. You could try checking the bucket's policy, but this requires that you are the bucket owner and that the bucket has a policy.

My app uses CakePHP 2.4 and I am only integrating a few S3 functions in the SDK. Once I have a more stable module, how do I contribute to that?

While we do not place third party integrations into the SDK itself, we would be happy to help promote third party integrations that make it easier to use the AWS SDK for PHP with other frameworks. Just let us know via the forums when it's done and we can take a look.

jeremeamia commented 11 years ago

We have created a few third-party modules ourselves (with community help), so please take a look at these to see what kind of things we have done.