I have an cloudinary_id stored in DB and want to delete this image from Cloudinary.
According documentation I call desctroy method on uploadApi with id which returns result OK. But as I see the image is still available. Dont understand it.
Tis is the code:
$cloudinary = new Cloudinary($config);
return $cloudinary->uploadApi()->destroy($file_id);
This code returns Cloudinary\Api\ApiResponse #d6b5 result => "ok"
Can somebody tell me please what is wrong with this code?
Cloudinary uses CDN to ensure fast delivery of the media resources. That being said, when deleting a media via API, you may need to pass the optional parameter "invalidation" set to true in order to invalidate that object in their CDN.
Here are their API documentation below:
https://cloudinary.com/documentation/image_upload_api_reference#destroy_method
https://cloudinary.com/documentation/admin_api#delete_resources
You may use either upload API or admin API. Both achieve the same result.
Anthony
Related
My site has a feature where users can upload a link to their google docs file. What I want to do is list all the uploaded links in a place. While doing that I need to show the name of the file that is associated with the link.
I can extract the file id from the link and make sure the link is of google docs. Now I need to find a way to get the filename from that. I tried going through the google developer API for google drive, but it is for uploading/doing anything only on the authorized docs. My issue here is, my users upload the files manually to their docs which I have no control over. All I get is a sharable link and somehow get the name out of it. In addition, a thumbnail will also help.
I have tried doing this, but it throws error
$url = "https://www.googleapis.com/drive/v3/files/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA";
// and
$url = "https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing"
$html= file_get_contents($url);
print_r($html);
A dummy link for anyone willing to help: https://docs.google.com/document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing
Since we are getting the URL to the file, we can do a couple of things -
get the id to the file
get what type of file is that
Before I explain how to do that, it is better to know that there can be 2 possible situations. One the file is a google docs file, the other google drive file. Those both start with different URLs.
$url = explode('/', Str::after(
Str::after($request->url, 'https://docs.google.com/'), 'https://drive.google.com/'
));
I am using 2 Str::after() to remove the unnecessary part from the URL. Then I am using explode to convert the URL into an array.
Since we have excluded the useless part from the URL, we are left with document/d/1G6N6FyXzg7plgEtJn-Cawo5gbghrS8z9_j_cvVqcEDA/edit?usp=sharing in an array form.
So, if we try to do $url[2], we get the id of the file. Also, "document" is also a good thing to note about. I use those to show proper images. There can be 5 different types of them (4 for google docs and 1 for google drive). Those are - document, spreadsheets, forms, presentation for google docs, and file for google drive. I would recommend everyone store these in the database so that extra calculations are not necessary while displaying it.
Now, to answer the actual part of the question. How to get the name. I have created a new model method to handle that.
public function name()
{
$key = config('app.google_api_key');
$url = "https://www.googleapis.com/drive/v3/files/{$this->file_id}?key={$key}";
$response = Http::get($url)->json();
return $response['name'] ?? 'Private File';
}
Don't forget to add your Google API key in the config file app.php (You need to create one). You can get your API key from Google Developer Console and create a project-specific key. Just to note that this key need not be belonging to the user of the URL.
Also, a thing to note here is that $response returns error code if the file is not set to visible to the public or the file is deleted.
I know that this api is working to get images but how about videos?
https://www.instagram.com/username/?__a=1
I was able to get the thumbnail of the video but not the source or the url itself.
When you make above API call it would return code in it. looks something like this: BWhyIhRDBCw
Whenever your media nodes has "is_video": true you can make following call:
https://www.instagram.com/p/{code}/?__a=1
for e.g.,
https://www.instagram.com/p/BWhyIhRDBCw/?__a=1
This would return another json. which will have video_url you are looking for.
sample:
"video_url": "https://scontent-bom1-1.cdninstagram.com/vp/437699b67172f450331fa732f0777b18/5A7FE0A0/t50.2886-16/20138822_486349355081174_1539674401849475072_n.mp4",
This url working in local machine but not on my remote server.
When i try to hit from remote server its returning html content.
To hit this api simply use volly library it will return json then u can parse json as per your need.
I have a roadblock here. I want to get the video duration from Cloudinary.
Is there any function I can use to get my desired result?
The Only option I found is using Cloudinary API's resource method. I am using the PHP Cloudinary API in this way:
$api = new \Cloudinary\Api();
$result = $api->resource("public_id",array("resource_type" => video","duration"=>true));
print_r($result);
This function gets most of the info of the video but not the video's duration.
I have also tried with PHP 'getID3' Library but it returns an error that says:
Remote files are not supported - please copy the file locally first
If you guys have any idea how to do this in Cloudinary or in PHP, please Share.
Thanks in advance.
Cloudinary supports returning more extensive information by setting the image_metadata parameter to true.
For example:
$result = $api->resource("public_id",array("resource_type" => "video","image_metadata"=>true));
This will also return the duration of the video.
I'm using the PHP SDK 2 for Amazon S3, in particular the UploadBuilder class to do multipart concurrent uploading of files. How, if you can, do you set the storage class of the file that you are uploading? When you do a regular putObject, you can set the storage class that you want the file to have. I want my files to be stored using reduced redundancy rather than the standard storage. Can I just use setOption to set a header like so?
setOption('x-amz-storage-class', 'REDUCED_REDUNDANCY')
From looking at the source of UploadBuilder it appears you may be able to set it using Metadata. Here's an example of setting an MD5 header from the source:
// If an MD5 is specified, then add it to the custom headers of the request
// so that it will be returned when downloading the object from Amazon S3
if ($this->md5) {
$params['Metadata']['x-amz-Content-MD5'] = $this->md5;
}
So, that would mean I would set it doing something like this:
setOption('Metadata', array('x-amz-storage-class' => 'REDUCED_REDUNDANCY'))
Can anyone confirm this is correct or am I way off base?
In the API docs for setOption, it says that the method sets "an option to pass to the initial CreateMultipartUpload operation". According to the API docs for createMultipartUpload, you should use the StorageClass param. So, you should be able to do the following with the UploadBuilder to set the storage class on your multipart upload:
->setOption('StorageClass', 'REDUCED_REDUNDANCY')
I want to access some function written in some php file on another server and receive the input, I have access to those server files so that I can change them for proper configuration, I have all the privilleges to do so, can anybody please guide me how can I do it, thank you
$result = file_get_contents("http://some.server/out.php");
and in this out.php
<?php
include 'some.php';
function();
I think you can implement web service or an api, and the output could be in xml or json read the content and use it on your website.
It is just Facebook graph API using URL
https://graph.facebook.com/Pepsi
The above link will fetch information regarding Facebook page of Pepsi.