Coder Social home page Coder Social logo

cloudinary-laravel's People

Contributors

asisayag2 avatar colbyfayock avatar cw-alihyder avatar cybersai avatar delaney avatar jackieros avatar jeremydunn avatar joshmanders avatar justinkekeocha avatar laravel-shift avatar mdhesari avatar miteyema avatar nova4005 avatar oscar-rey-mosquera avatar parth391 avatar peteeveleigh avatar rnambaale avatar saineshmamgain avatar slimgee avatar unicodeveloper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloudinary-laravel's Issues

Call to undefined method Cloudinary\Api\Admin\AdminApi::deleteResourcesByPrefix()

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;

    }

Transfer existing images from s3

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?

Invalid configuration, please set up your environment

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.

more x-cld-image component attributes and destination folder parameter in attach media

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 ?

Upload to custom folder and save to Media table

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.

Can't find doc's on how to delete a file from my API

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?

Cannot get image URL from Storage Facade

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.

Using deprecated AdminAPI functions from cloudinary/cloudinary_php package

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.

For more info see here

#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!

How to set it up in .env

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?

How to use storeOnCloudinaryAs method with cloudinary-laravel?

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!

Upload method doesn't support file/image name

No provision to specify image name using the upload method

cloudinary()->upload($request->file('file')->getRealPath(), [
               'folder' => 'posts',
               'transformation' => [
                            'width' => 1920,
                            'height' => 1280
                ]
     ])->getSecurePath();

specify signature_algorithm in the config/cloudinary.php

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

Invalid Signature

Getting error message:

"message": "Invalid Signature ea0c21525ceea9db4bd441005d11ebd8a7065dde. String to sign - 'public_id=kjusjhapqdhssjqhhu6c\&timestamp=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();

How to check if url to image is valid and file exists?

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!

Fetching images in blade view

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.

Possibility to download from external URL?

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.

@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):

  • User enters details in the profile picture form to be updated.
  • Before the actual update is done, you retrieve the public_id or file_name attached to the user in the users table or the media table which comes with the Cloudinary package.
  • Use the public_id to make a destroy call to delete the previous image.
  • upload the new image to Cloudinary and update the respective tables with the new values.

Something along these lines should probably work.

Originally posted by @dela-dels in #40 (comment)

Issue with Upload Button Directive

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.

Blade Component Discussion

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:

  1. Is this even something that the team or the community would be interested in?
  2. Does this open a can of worms better left to an independent package? (my first thoughts actually)
  3. It seems the URL returned is not parsed exactly as it should be.
    For example, instead of returning https://res.cloudinary.com/dtm8qhbwk/image/upload/c_scale,h_300,w_300,f_auto,q_60/briafgn2sey90arhgfgp,
    it returns
    https://res.cloudinary.com/dtm8qhbwk/image/upload/c_scale,h_300,w_300/f_auto/q_60/briafgn2sey90arhgfgp.
    Everything still seems to work as expected, but I wanted to be sure this was expectable before I dig too deep into cloudinary\cloudinary_php to find the source of this behavior. I could be going about adding this functionality complete wrong!
  4. When reading the 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.

Example Change

@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.

Example Usage and Result

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.

Delete previous image and upload new

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();
        
    }

How do I configure credentials ?

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!

Generating Secure Url

@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.

Flysystem problem for Laravel 9

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

Failed to copy image using Storage::disk('cloudinary')->copy() method

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);
}

This is the error produced:
Untitled

Somehow localhost is added in the url

Support PHP 8

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].

detachMedia deletes ALL images attached to an entity

https://github.com/cloudinary-labs/cloudinary-laravel/blob/ab0dc2d2dfefbeb67c7b282b72e6203802c36582/src/MediaAlly.php#L82

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...

How do I delete an Image using the image URL from my Controller

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.

Add overlay image

Hi,

Is it possible to add a watermark/overaly image to another image or video using this package?

Some methods fail if used from storage extension

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:

  • delete
  • update
  • copy
  • rename

Unable to install on Laravel ^8.0

[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

How to check if url to image is valid and file exists?

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.