Skip to content
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

Update access mode method not available in SDK #358

Open
3 of 9 tasks
brandon14 opened this issue May 26, 2022 · 10 comments
Open
3 of 9 tasks

Update access mode method not available in SDK #358

brandon14 opened this issue May 26, 2022 · 10 comments
Assignees

Comments

@brandon14
Copy link

Bug report for Cloudinary PHP SDK

Before proceeding, please update to latest version and test if the issue persists

Describe the bug in a sentence or two.

In the documentation or the admin API, it references an API call to modify the access_mode on an asset as described here using the PHP SDK, but I am unable to find that API call (updateResourcesAccessMode) in the PHP SDK.

Issue Type (Can be multiple)

  • Build - Can’t install or import the SDK
  • Performance - Performance issues
  • Behaviour - Functions aren’t working as expected (such as generate URL)
  • Documentation - Inconsistency between the docs and behaviour
  • Other (Specify)

Steps to reproduce

  1. Install PHP SDK (I am using v2.7.1 on PHP 8.1.5).
  2. Try to make a call to updateResourcesAccessMode($access_mode, $options = []); as described in the above mentioned documentation.
  3. That method does not exist on the AdminApi object.

Error screenshots or Stack Trace (if applicable)

image
image

Fatal error: Uncaught Error: Call to undefined method Cloudinary\Api\Admin\AdminApi::updateResourcesAccessMode() in <redacted>\cloudinary-flysystem\src\CloudinaryAdapter.php:446
Stack trace:
#0 <redacted>\cloudinary-flysystem\test.php(62): Brandon14\CloudinaryFlysystem\CloudinaryAdapter->setVisibility('sample.jpg', 'private')
#1 {main}

Next League\Flysystem\UnableToSetVisibility: Unable to set visibility for file sample.jpg. Call to undefined method Cloudinary\Api\Admin\AdminApi::updateResourcesAccessMode() in <redacted>\cloud
inary-flysystem\vendor\league\flysystem\src\UnableToSetVisibility.php:33
Stack trace:
#0 <redacted>\cloudinary-flysystem\src\CloudinaryAdapter.php(454): League\Flysystem\UnableToSetVisibility::atLocation('sample.jpg', 'Call to undefin...', Object(Error))
#1 <redacted>\cloudinary-flysystem\test.php(62): Brandon14\CloudinaryFlysystem\CloudinaryAdapter->setVisibility('sample.jpg', 'private')
#2 {main}
  thrown in <redacted>\cloudinary-flysystem\vendor\league\flysystem\src\UnableToSetVisibility.php on line 33

Operating System

  • Linux
  • Windows
  • macOS
  • All

Environment and Frameworks (fill in the version numbers)

  • PHP Cloudinary SDK version - 2.7.1
  • PHP Version - 8.1.5
  • Framework (Laravel, Symphony, etc) - N/A

Repository

N/A

@brandon14 brandon14 changed the title Update Access Mode Methods Not Available In SDK Update access mode method not available in SDK May 26, 2022
@brandon14
Copy link
Author

If there is another way to modify the access_mode (NOTE: Not the access_control parameter that is available via the update() method, then that would be acceptable. just wanted to make sure that the omission of this functionality, and divergence from the documentation, was intentional.

@aleksandar-cloudinary
Copy link

aleksandar-cloudinary commented May 27, 2022

Hi @brandon14 - Thanks for getting in touch. That method is indeed not supported for the PHP SDK so it does appear that the Documentation is the part that should be updated - I'll speak with our team about that internally. We plan to sunset the Access Mode feature so it's not present in all SDKs and especially the new V2 SDKs.

In terms of potential workarounds, what you could try is to send a direct API call to Cloudinary (not using the SDK) passing the relevant parameters to update the access mode of that asset. For example, you can use cURL or any HTTP library and make a POST request to /resources/:resource_type/upload/update_access_mode and pass the required/optional parameters as per (https://cloudinary.com/documentation/admin_api#update_access_mode). The Admin API uses Basic Authentication as the authentication method so that can be passed quite easily to the HTTP client itself.

For example, via cURL (you'll need to substitute the placeholders in all caps):

curl -X POST https://API_KEY:[email protected]/v1_1/CLOUD_NAME/resources/image/upload/update_access_mode -H "Content-Type: application/json" --data '{"public_ids":["MY_PUBLIC_ID"],"access_mode":"public"}'

Would you be able to try this out and let me know if it works for you?

@aleksandar-cloudinary aleksandar-cloudinary self-assigned this May 27, 2022
@brandon14
Copy link
Author

The cURL request does work, and this could be a potentially viable solution. If plans are to sunset this functionality that is fine. The reason I ask is I was writing an updated Flysystem adapter for Cloudinary, and it optionally supports altering visibility, but most of the adapters I have seen for Cloudinary just omit the functionality. I was thinking if it was as easy an API call like that, then I would add support for that, but it's not a big deal. I mainly wanted to bring it up as well to make sure it wasn't something overlooked, or something wrong in the documentation.

@aleksandar-cloudinary
Copy link

Thanks, @brandon14 - I agree, since it's not supported it should be removed from the Documentation's code examples (I'll update that from our side) to avoid confusion as to whether the Docs is right or the code is missing the implementation.
If you just want an asset to be Restricted and in some cases Public, then you could use Access Control instead. On Free accounts, you won't have an Access Key to generate a valid token for accessing Access Control Restricted assets, but you can block access to the file by setting Access Control on the asset and then when you need to make it Public you can do that too.

@brandon14
Copy link
Author

@aleksandar-cloudinary Thanks for the reply. This is good to close as long as the documentation and examples are cleaned up.

@aleksandar-cloudinary
Copy link

@brandon14 - You're welcome. - Absolutely - we'll update the docs to remove that to avoid such confusion going forward.

@lk77
Copy link

lk77 commented May 5, 2023

i have the exact same issue, passing access_mode to Cloudinary::admin()->updateUploadPreset() does not work

@aleksandar-cloudinary
Copy link

@lk77 Hi, Indeed, that option is not one of the supported Upload API parameters in the new SDKs hence it's not passed in the request from the SDK to Cloudinary. That said, you should see the Access Mode option in the UI (Settings > Upload tab > Upload Presets) and be able to set it there for the upload preset you want to update.

@lk77
Copy link

lk77 commented May 5, 2023

@aleksandar-cloudinary yes but it fallback to public every time i update the preset with the admin api,

it should :

  • either set the access_mode
  • or don't set the access_mode but don't override it and keep what the user put with the ui

Also a patch route would be useful, in the end i only want to update the notification_url

Having to retrieve the preset, modify the url and send it back to cloudinary adds an unnecessary step i think

@aleksandar-cloudinary
Copy link

@lk77 Yes, the API performs an update so unless you pull the details, modify the object and send it back in the update() call, it will overwrite with the relevant parameters in your last request. There are long-term plans in regards to deprecating access_mode in favour of access_control hence why the new version of the SDKs do not support access_mode, unlike version 1 of the SDKs. PHP is the first backend V2 SDK that has been released currently, while V1 SDKs like NodeJS still support that parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants