cloudinary-community / cloudinary-laravel Goto Github PK
View Code? Open in Web Editor NEWLaravel SDK for Cloudinary
License: MIT License
Laravel SDK for Cloudinary
License: MIT License
I'm using spatie/media-library to handle my model's media.
Everything is working OK, with the only exception to when i try to delete a media item, i receive the following error:
Call to undefined method Cloudinary\Api\Admin\AdminApi::deleteResourcesByPrefix()
The rest of the stack traces shows this message:
CloudinaryLabs\CloudinaryLaravel\CloudinaryAdapter::deleteDir
vendor/cloudinary-labs/cloudinary-laravel/src/CloudinaryAdapter.php:189
/**
* Delete a directory.
* Delete Files using directory as a prefix.
*
* @param string $dirname
*
* @return bool
*
* @throws ApiError
*/
public function deleteDir($dirname)
{
$this->adminApi()->deleteResourcesByPrefix($dirname);
return true;
}
'transformation' => [
'quality' => auto,
]
What is the best approach to handle images currently stored in a s3 bucket?
Do I need to write a script looping over all images and uploading to cloudinary?
Hi,
I am unable to configure this plugin;
I have these values in my .env file.
CLOUDINARY_URL=cloudinary://XXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXX@cloudname
CLOUDINARY_UPLOAD_PRESET=ml_default
CLOUDINARY_NOTIFICATION_URL=
"Unsigned uploading enabled" is also enabled in the Cloudinary upload preset section.
And in my controller, I have
$uploadedFileUrl = cloudinary()->uploadVideo($request->file('vidfile')->getRealPath())->getSecurePath();
Please let me know what am I missing.
Its not included in the documentary, How can i resize, transform media with the attachMedia() function? I checked the function and i saw it only receive one parameter
Hey, I have been struggling for hours and I still haven't found any solution with this one.
I can't find a way to add more attributes in x-cld-image
. This is the component:
@php
echo cloudinary()->getImageTag($publicId ?? '')->scale($width ?? '', $height ?? '')->serialize();
@endphp
Apparently, I can only add width
and height
but what if I want the image to be rounded? or change the file format?
Last but not least, I did $file->storeOnCloudinaryAs('logos', 'user_logo')
to upload the file user_logo
in the cloudinary folder logos
and then I did $user->attachMedia($file)
to attach the image to the specified user model. However, this resulted in having user_logo
both in root cloudinary directory and in logos
folder.
Maybe add another parameter to attachMedia
, ie. folder
so that we can choose destination folder for upload ?
Can there be a helper to upload images to custom cloudinary folder $uploadedFile = $file->storeOnCloudinary(Auth::user()->name);
and at the same time handle the saving to the media
table.
Currently I have to use that function and still write more code to save to a media table.
More like $uploadedFile = $file->attachOnCloudinary(Auth::user()->name);
Thank you.
I'm trying to have an edit function and if the user changes their image I wanna delete the former one from the Cloudinary storage but couldn't find any resources.
i'm storing images using 'profile_pic' => Cloudinary::upload($request->file('profile_pic')->getRealPath())->getSecurePath(),
using: Laravel 9
can any one point me to the right place?
how can I delete the images by using a public ID also why the documentation does not explain on it
For the getPublicId() - i have to upload it and it will get the public_id but i want to get public_id of the old image to delete it and update a new one. How can i do that - can you give me an example??
The docs says can get the image URL with the public id via:
$url = Storage::disk('cloudinary')->url($publicId);
But when using that, it throws the error: This driver does not support retrieving URLs.
Seems the CloudinaryAdapter
class doesn't implement getUrl
method so Laravel throws that error.
Moreover, when calling the toUrl
method of the BaseMediaAsset
class doesn't return a string, it returns a GuzzleHttp\Psr7\Uri
object.
It seems that the CloudinaryAdapter uses the deprecated resources method $api->resource()
from cloudinary__php v1.x. However, the currently used method no longer exists in the new major version of cloudinary__php v2.x. Instead, the $api->assets()
method is now used.
#SDK 1.x
require "cloudinary.php";
require "api.php";
$api = new \Cloudinary\Api();
$result = $api->resource("sample");
Becomes:
#SDK 2.x
use Cloudinary\Api\Admin\AdminApi;
$result = (new AdminApi())->asset("sample");
Since the current cloudinary-laravel version requires at least version 2.0 of cloudinary/cloudinary_php, I currently get an error when using the CloudinaryAdapter class.
Am I seeing this correctly, that the CloudinaryAdapter is incorrect or am I doing something wrong?
Thank you!
I see these are needed in the .env
CLOUDINARY_URL=xxxxxxxxxxxxx
CLOUDINARY_UPLOAD_PRESET=xxxxxxxxxxxxx
CLOUDINARY_NOTIFICATION_URL=
And it says those are on the Account Dashboard but I can't see them I only have
Cloud name:
API Key:
API Secret:
API Environment variable:
Base delivery URL:
Secure delivery URL:
API Base URL:
The names don't match, except for the API Environment variable is the CLOUDINARY_URL, but other that one I don't know what goes where.
What do I put for the other two?
Using cloudinary-labs/cloudinary-laravel under Laravel 8 app I try to upload file
under subdirectory and custom file name I did not catch what is ->file parameter in sample:
$result = $request->file->storeOnCloudinaryAs('lambogini', 'prosper');
as running the cope above I got error :
Call to a member function storeOnCloudinaryAs() on null",
Also I tried to run:
$pageUploadedFile = $request->file('image');
...
$uploadedFileUrl= $pageUploadedFile->storeOnCloudinaryAs('lambogini', 'prosper');
But I got error :
"message": "Page creation : Method Illuminate\\Http\\UploadedFile::storeOnCloudinaryAs does not exist."
Trying to make
$uploadedFileUrl = cloudinary()->storeOnCloudinaryAs('lambogini', 'prosper')->upload($request->file('image')->getRealPath())->getSecurePath();
I got
"Call to undefined method CloudinaryLabs\\CloudinaryLaravel\\CloudinaryEngine::storeOnCloudinaryAs()",
Which is the valide way to run storeOnCloudinaryAs method?
Thanks!
No provision to specify image name using the upload method
cloudinary()->upload($request->file('file')->getRealPath(), [
'folder' => 'posts',
'transformation' => [
'width' => 1920,
'height' => 1280
]
])->getSecurePath();
Hello
It will be great if we can specify some more parameters in the cloudinary.php conf file as mentioned here.
Actually, i am trying to specify the signature_algorithm
parameter, is there any way to do it with the current package version ?
Thank you
Getting error message:
"message": "Invalid Signature ea0c21525ceea9db4bd441005d11ebd8a7065dde. String to sign - 'public_id=kjusjhapqdhssjqhhu6c\×tamp=1610426837'.", "exception": "Cloudinary\\Api\\Exception\\AuthorizationRequired"
When using:
$result = cloudinary::destroy($public_id);
Please note that uploading files works just fine:
$uploaded_file_Url = Cloudinary::upload($request->file('file')->getRealPath(), [ 'folder' => auth()->user()->id, 'transformation' => [ 'quality' => 'auto', 'fetch_format' => 'auto' ] ])->getSecurePath();
When I tried to update my laravel 8 app to 9
it says Cloudinary is not compatible with Laravel 9.
Hello,
I have links to cloudinary-laravel images in my db and search which is valid way to check
if url to image is valid and file exists?
"cloudinary-labs/cloudinary-laravel": "^1.0",
"laravel/framework": "^8.12",
Thanks!
Hello !
I have properly setup the enviroment for cloudinary-laravel and I have confirmed it by running php artisan cloudinary:fetch public_id
. In this case I get the URL of the image successfully.
My question is: how can I fetch any image in my blade.php file with given options?
This was really simple with cloudder
, all I had to do is write <img src="{{ Cloudder::show($public_id, $options) }}">
and the image was retrieved.
Delete video not working
Right now we need the file on our local disk to upload to Cloudinary (or maybe I did not find how to do it with yet). Adding from an external source (e.g. Image URL) will be very helpful.
@hotfuzz123 I think the only way you can do this right now is if you are storing the public_id(which could be the filename) of the uploaded file in your database. Then you can use that to delete the resource from Cloudinary by supplying the public_id
to the destroy()
method of the Cloudinary API.
So the flow could be something like this (using the example of a user updating their profile picture):
public_id
or file_name
attached to the user in the users
table or the media
table which comes with the Cloudinary package.public_id
to make a destroy
call to delete the previous image.Something along these lines should probably work.
Originally posted by @dela-dels in #40 (comment)
I keep getting the following error during installation:
The directive name [cld-upload-button] is not valid. Directive names must only contain alphanumeric characters and underscores.
I've used the Cloudinary service on a few other projects and was pleasntly surprised to find this repo after starting a personal project using Laravel 8. So far, it works great and I don't have any real issues. But I ran across the Blade Components while browsing through the README and started playing with the image component. Right off I noticed that it was not very flexible and that leads into my discussion points.
Although I know that we can perform transformations on an image during upload (per closed issue #4), I was wondering how hard it would be to expand upon the current Blade Component and bring a bit more flexibility to it. It turns out that it's not that hard and to me is a sign that I've missed or overlooked something. But before I go forking anything and wasting every ones time, I wanted to ask a few questions first:
https://res.cloudinary.com/dtm8qhbwk/image/upload/c_scale,h_300,w_300,f_auto,q_60/briafgn2sey90arhgfgp
,https://res.cloudinary.com/dtm8qhbwk/image/upload/c_scale,h_300,w_300/f_auto/q_60/briafgn2sey90arhgfgp
.cloudinary\cloudinary_php
to find the source of this behavior. I could be going about adding this functionality complete wrong!contributing.md
it states "Your patch won't be accepted if it doesn't have tests.". I think this is completely acceptable, but although there is a directory listed in composer.json
and there is a phpunit.xml
that points to the same directory (/tests), there doesn't actually seem to be a tests directory in the repo. Once again, I must be overlooking something fairly obvious.@php
echo cloudinary()
->getImageTag($publicId ?? '')
->scale($width ?? '', $height ?? '')
->format($format ?? 'auto')
->quality($quality ?? 'auto')
->serialize();
@endphp
The above example is the changes I made to /resources/views/components/image.blade.php
. As you can see, I keep the similar format used with the scale
option. If $format is not specified in the component, it will default to f_auto
. If no $quality is specified, it will default to q_auto
as well.
Usage
// CanineController.php
public function show(Canine $canine)
{
$canine = Canine::findOrFail($canine->id);
return view(
'canine.show',
[
'canine' => $canine,
'profile_image' => $canine->fetchAllMedia(),
]
);
}
// show.blade.php
<x-cld-image public-id="{{ $profile_image[0]->file_name }}" width="300" height="300" quality="60"></x-cld-image>
Result
<img src="https://res.cloudinary.com/dtm8qhbwk/image/upload/c_scale,h_300,w_300/f_auto/q_60/briafgn2sey90arhgfgp">
Many thanks goes to the whole team for this project. Keep up the great work! Input, scolding and thoughtful banter welcome to the discussion above.
if($request->hasFile('image')){
$public_id = Cloudinary::upload('public_id');
$url = Storage::disk('cloudinary')->url($public_id);
$image_exist = Category::select('image')->where($public_id);
Cloudinary::destroy($image_exist);
Cloudinary::upload($request->file('image')->getRealPath(), ['folder' => 'Categories',]);
$image = $request->file('image')->getRealPath();
}
I have also tried like this:
Cloudinary::destroy($article->image);
$article['image'] = Cloudinary::upload($request->file('image')->getRealPath(),[
'folder' => 'Articles',
])->getSecurePath();
And so this method works but then it doesn't show me the images in Laravel, but if I delete and update the image in Cloudinary:
if($request->hasFile('image')){
Cloudinary::destroy($article->image);
$article['image'] = Cloudinary::upload($request->file('image')->getRealPath(),[
'folder' => 'Articles',
])->getPublicId();
}
Hi,
How do I configure the credentials once I install the package ?
CLOUDINARY_URL=xxxxxxxxxxxxx
CLOUDINARY_UPLOAD_PRESET=xxxxxxxxxxxxx
CLOUDINARY_NOTIFICATION_URL=
Where as I got these credentials from cloudinary management console.
Cloud Name: xxxx
API Key: xxxxx
API Secret: xxxxx
Env Variable: cloudinary://xxxxx
Could you please help what am I supposed to set ?
Thanks!
@unicodeveloper I want thank your team for this package. Great work!
Please is it possible to generate secure temporary URL using this package. So I can access my images if made private.
GuzzleHttp\Exception\RequestException
cURL error 60: SSL certificate problem: self signed certificate in certificate chain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.cloudinary.com/v1_1/dnvc45kxn/auto/upload
Hey,
in version 1.0.5
the CloudinaryAdapter
still uses the NotSupportingVisibilityTrait
which doesn't exist anymore in Flysystem 3. The latter is used in Laravel 9.
Best regards,
Chris
Laravel Version: 9.25.1
PHP Version: 8.1.6
public static function copyCoverImageToPermanentDirectory(Post $post, string $coverImageUrl): string
{
$destinationPath = 'posts/' . $post->id . '/cover';
Storage::disk('cloudinary')->copy($coverImageUrl, $destinationPath); // this produces an error
// \Cloudinary::uploadApi()->upload($coverImageUrl, ['public_id' => $destinationPath]); // this is the working method
return Storage::disk('cloudinary')->url($destinationPath);
}
Somehow localhost is added in the url
Currently, composer upgrade gives the following error when using PHP 8.
- cloudinary-labs/cloudinary-laravel 1.0.0 requires php ^7.0 -> your php version (8.0.0) does not satisfy that requirement.
- cloudinary-labs/cloudinary-laravel[1.0.1, ..., 1.0.2] require php ^7.2 -> your php version (8.0.0) does not satisfy that requirement.
- Root composer.json requires cloudinary-labs/cloudinary-laravel ^1.0 -> satisfiable by cloudinary-labs/cloudinary-laravel[1.0.0, 1.0.1, 1.0.2].
This method is problematic. It gets ALL the images associated to the entity, and deletes them all...
Need to have an if statement to check for nullness of $media
param, if not null, only delete given media, else then delete all.
For a destructive action like delete all media, it should even be consider to have a separate method just for that...
I have been able to store user profile image to cloudinary with the image url stored in my database. Now, If the user wants to update his/her profile image, I want it to delete the existing image before storing the new one.
How do I do this using this your library.
Below is what I have done already with comment on what I am trying to achieve.
`if ($request->hasFile('photo')) {
if ($user->profile_photo_path) {
// How do I delete the existing image within this if block
}
// Upload the new Image File to Cloudinary with One line of Code
$uploadedFileUrl = Cloudinary::upload($request->file('photo')->getRealPath(),[
'folder' => 'creative_movers/users/profile/images/'
])->getSecurePath();
$user->profile_photo_path = $uploadedFileUrl;
} $user->update()`
How do I achieve this please.
Hi,
Is it possible to add a watermark/overaly image to another image or video using this package?
I need to delete an image
Any method called from Storage::disk('cloudinary')
which passes thru the League\Flysystem\Filesystem
and hits the assertPresent
method of the aforementioned class will fail to achieve anything (for most setups). This is because assertPresent
calls the CloudinaryAdapter@has
method, which will cause a failure if you do not have the target path locally...
Example methods that will fail:
There is no support for Laravel Lumen
[URGENT]
Hi, I am unable to install on Laravel 8.0. I am getting this error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for guzzlehttp/guzzle ^7.0.1 -> satisfiable by guzzlehttp/guzzle[7.0.1, 7.0.x-dev, 7.1.x-dev].
- cloudinary/cloudinary_php 2.0.0-beta6 requires guzzlehttp/guzzle ^6 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- cloudinary/cloudinary_php 2.0.0-beta6 requires guzzlehttp/guzzle ^6 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- Conclusion: remove cloudinary-labs/cloudinary-laravel 1.0.0|install guzzlehttp/guzzle 6.5.x-dev
- Conclusion: don't install guzzlehttp/guzzle 6.5.x-dev
- cloudinary-labs/cloudinary-laravel 1.0.0 requires cloudinary/cloudinary_php 2.0.0-beta6 -> satisfiable by cloudinary/cloudinary_php[2.0.0-beta6].
- Installation request for cloudinary-labs/cloudinary-laravel ^1.0 -> satisfiable by cloudinary-labs/cloudinary-laravel[1.0.0].
My composer.json
"require": {
"php": "^7.3",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"spatie/laravel-sitemap": "^5.8"
},
"require-dev": {
"facade/ignition": "^2.0",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0"
},
It only works when I downgrade the Laravel Framework to 7.0 and guzzle to 6.3. Please help me fix the issue.
Thanks
i want to resize and do many transformation with my image but i cant find any example related to it on the readMe file
Hello,
I have links to cloudinary-laravel images in my db and search which is valid way to check
if url to image is valid and file exists?
"cloudinary-labs/cloudinary-laravel": "^1.0",
"laravel/framework": "^8.12",
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.