Delete URL TO PNG Image on API cloudinary.uploader.destroy() ?

Comments

9 comments

  • Avatar
    Aleksandar Kostadinov

    Hi,

    The public_id would be the URL you supply i.e. - http://localhost:8000/rate/shot/5bba1bea7dd99159eb7c421b/5edce8950043d6085acf2485/1592750063/url2png/viewport%3D1200x628%7Cfullpage%3Dfalse

    Please note that since the 'type' of the asset is not the default, 'upload', you'll need to add 'type: "url2png"' in your destroy( ) call too. Otherwise, it'll default to type 'upload' and you'll receive a not found response.

    0
    Comment actions Permalink
  • Avatar
    Arbortree Creations

    Hiya

    I did try this like you explained

    Actual full URL 
    https://res.cloudinary.com/thearsenalreview/image/url2png/v1592833342/http://localhost:8000/rate/shot/5bba1bea7dd99159eb7c421b/5d0750d4643368183ccd6155/1592833342/url2png/viewport%3D1200x628%7Cfullpage%3Dfalse

    My function call on server (NOTE -> I upload the image right above no issues, using cloudinary.v2.uploader.upload())


    console.log("paramURL ", paramURL); // Console log below

    http://localhost:8000/rate/shot/5bba1bea7dd99159eb7c421b/5d0750d4643368183ccd6155/1592833342/url2png/viewport%3D1200x628%7Cfullpage%3Dfalse


    let myResult = await cloudinary.v2.uploader.destroy(paramURL, { type: "url2png" });

    // console log result below

    RESULT { result: 'not found' }

    Daniel

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Daniel,

    Thanks for this, I see it in the logs. The Public ID in such a case is stored as the URL decoded version (i.e. the = and pipe characters are as-is rather than URL encoded which is why it doesn't find the resource). Could you try using the below as the public_id? -

    http://localhost:8000/rate/shot/5bba1bea7dd99159eb7c421b/5d0750d4643368183ccd6155/1592833342/url2png/viewport=1200x628|fullpage=false

    1
    Comment actions Permalink
  • Avatar
    Pavel Burylichau

    Hello,

    I am using PHP SDK for working with Cloudinary. Before every screenshot, I try to clear the cache if a site previously was pictured. My sites are covered by a firewall, so for having a screenshot I turn it off. Then try to clear cache. Then do screenshot.

    But as a result, I am getting some sites pictured like they are under the firewall, while I can freely open them without any VPN like it would be published to the web. During an attempt to delete no logs because it previously was screenshotted. 

    How I can clear cache for a such URI?

    My code looks like 

    private function maybe_clear_screenshot_cache( string $source_link ): void {
    try {
    \Cloudinary\Uploader::destroy( $source_link, [ 'type' => 'url2png' ] );
    } catch ( Upload_Error $e ) {
    \error_log( "A screenshot cache does not exist for link: $source_link" );
    }
    }
    0
    Comment actions Permalink
  • Avatar
    Pavel Burylichau

    Small adding. 

    After I've taken a screenshot, I upload it to CDN.

    So, I guess that when cloudinary makes the screenshot it is additionally saved somewhere, and after the next attempt is retrieved from that cache, isn't it?

    Actual code for doing screenshot and then uploading it 

    public function make_screenshot( string $host, string $viewport ): string {
    $source_link = "https://{$host}?a=b/url2png/viewport={$viewport}|fullpage=true";

    $this->maybe_clear_screenshot_cache( $source_link );

    return cloudinary_url(
    $source_link,
    [
    'sign_url' => true,
    'secure' => true,
    'type' => 'url2png',
    ]
    );
    }

    ...
    $response = \Cloudinary\Uploader::upload(
    $screenshot_link,
    [
    'public_id' => $filename,
    'folder' => $this->folder,
    'use_filename' => true,
    'sign_url' => true,
    'overwrite' => true,
    ]
    );
    ...
    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Pavel,

    The asset itself will be stored in your Cloudinary account and also cached on the CDN. When deleting an asset via destroy( ) it will delete it from your Cloudinary account but unless you include a specific parameter, the CDN cache would remain. When deleting using the destroy( ) method, you should include the 'invalidate' parameter set to True in your call. That will request Cloudinary to clear the CDN cache for any copies for this image. If you have an example of an image you deleted with invalidation but the cache wasn't cleared then please share that with us. Either here, or via a support ticket directly (https://support.cloudinary.com/hc/en-us/requests/new) and we'll have a look at the logs from our side.

    0
    Comment actions Permalink
  • Avatar
    Pavel Burylichau

    I have added it. Didn't helped.

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Could you please share a specific example of a destroy call and parameters you passed (such as public_id) so that we can check the logs? If you don't want to share it in this thread please use the link in my previous message to send us a ticket directly with the details.

    0
    Comment actions Permalink
  • Avatar
    Arbortree Creations

    Thanks Aleksandar

    I used the decodeURIComponent() javascript fucntion. 

    This is what I missed.

    Daniel

    0
    Comment actions Permalink

Please sign in to leave a comment.