cloudinary-community / cloudinary-laravel

Laravel SDK for Cloudinary
MIT License
255 stars 71 forks source link

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

Open jedymatt opened 1 year ago

jedymatt commented 1 year ago

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

unicodeveloper commented 7 months ago

@jedymatt Please do you still have an issue here?

jedymatt commented 7 months ago

@unicodeveloper Unfortunately, I stopped developing the app that uses cloudinary so I don't know if it has been fixed or not. Skimming through the release page, the issue is probably here.

As the snippet above, where the commented line is, that is the working code, which I got from the copy method of CloudinaryAdapter.

https://github.com/cloudinary-devs/cloudinary-laravel/blob/adc7f2559f30c5503901a1ab535a34477fddf24e/src/CloudinaryAdapter.php#L157C1-L162C6

The problem was that when using the Storage facade, the copy method fails because the localhost is prepended to the cloudinary url or the cloudinary url is appended to the localhost .