Using the pHash option while using Active Storage

Comments

5 comments

  • Avatar
    Daniel Mendoza

    @Brian

    I apologize for getting to this so late. With Active storage you can't pass in upload parameters in the call, so the only way to do this would be to set a global upload preset in the account that has phash set to true which will be applied to all uploads. Then when the response is returned you can try to view the phash value. I haven't investigated if there exists a callback to view the upload response but sounds like it would possible since it was available pre-active storage.

    0
    Comment actions Permalink
  • Avatar
    Brian Aberle

    @daniel I honestly didn't expect a response at all so glad to have one!

    My co-worker actually found a good approach using the Api module along the same lines you're talking about. 

    Basically uploading the image using Active storage then in a life cycle method to call the following:

    response = Cloudinary::Api.resource(user.photo.key, phash: true)
    response['phash']
    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Brian,

    Yes, that is one way, to retrieve it via the 'resources' method after the image has been uploaded.

    The approach Daniel mentioned would include setting up an upload preset which has the "Perceptual hash" option toggled 'On' from the options. Screenshot below.

    Using this approach, the pHash value would be returned in the upload response and thus not require a second API call. You can then set that upload preset as the default for image uploads for your account and it'll be applied automatically. Please see the following support article with details about this. https://support.cloudinary.com/hc/en-us/articles/208097215-How-can-I-add-upload-options-when-uploading-via-the-Media-Library-

    0
    Comment actions Permalink
  • Avatar
    Brian Aberle

    Hey Aleksandar,

    We tried turning that on and giving it a test a run but we only got back the active storage record.

    I may have been retrieving the response wrong though.

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Brian,

    Do you have access to the raw response or only the active storage record?

    Of crouse, since you have a working solution you can continue with this, but perhaps if we can get the upload approach working it'll be one to consider using going forward.

    0
    Comment actions Permalink

Please sign in to leave a comment.