Skip to main content

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

Comments

13 comments

  • 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
  • Arbortree Creations

    Hiya

    I did try this like you explained

    Actual full URL 
    https://res.cloudinary.com/<cloud_name>/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
  • 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
  • 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
  • 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
  • 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
  • Pavel Burylichau

    I have added it. Didn't helped.

    0
  • 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
  • Arbortree Creations

    Thanks Aleksandar

    I used the decodeURIComponent() javascript fucntion. 

    This is what I missed.

    Daniel

    0
  • Arbortree Creations

    Hello.

    I would like to re-open this thread as having strange behaviours again which I cannot seem to figure out.

    I can start with saying you really need to add some more content to the documentation so I dont waste hours messing and waste your time asking. Theres nothing in here about viewport, and there should be, with many more examples, so easy to add.
    https://cloudinary.com/documentation/url2png_website_screenshots_addon

    Lets look at this next urltopng call.
    https://res.cloudinary.com/<cloud_name>/image/url2png/https://www.thearsenalreview.com/url2png/viewport%3D1200x632
    When I download the image it is not 1200 x 632 , instead its 1200 x 698. This is the case with all my calls, the height is off ?



    Some other attempts


    https://res.cloudinary.com/<cloud_name>/image/url2png/https://www.thearsenalreview.com/url2png/viewport%3D1200x628%26fullpage%3Dfalse

    https://res.cloudinary.com/<cloud_name>/image/url2png/https://www.thearsenalreview.com/url2png/viewport=1200x628&fullpage=false

    https://res.cloudinary.com/<cloud_name>/image/url2png/https://www.thearsenalreview.com/url2png/viewport=1200x628

    Daniel

    0
  • Shirly Manor

    Hi Daniel,

     

    The `viewport` option is an option by the url2png plugin. you can read more about it here.

    Our best practice would be to use the cloudinary manipulation.

    For example in NodeJS:

    ```

    cloudinary.image("https://www.thearsenalreview.com", {height: 632, width: 1200, crop: "fill", type: "url2png"})

    https://res.cloudinary.com/<cloud_name>/image/url2png/w_1200,h_632/https://www.thearsenalreview.com

     

    Please let me know if that works,

    0
  • Daniel Gadd

    That doc is very useless here for me.

    Just tried your shared code above and that's not working.
    https://res.cloudinary.com/<cloud_name>/image/url2png/w_1200,h_632/https://www.thearsenalreview.com

    The page is squashed. We need a view port !

    0
  • Erwin Lukas

    Hi again Daniel :)

    I believe you've also opened a ticket to us and had it resolved.
    For everyone's benefit who may come across to this page in the future, `viewport` url2png parameter can be passed in the URL. This would be the final URL look like:
    https://res.cloudinary.com/<cloud_name>/image/url2png/https://www.thearsenalreview.com/pick/shot/5f7622710043d6085a118d1c/5f91cd6057d105001797518a/1603392317/url2png/viewport=1200x628|fullpage=false

    Regards,
    Erwin Lukas

    0

Post is closed for comments.