cloudinary-laravel
cloudinary-laravel copied to clipboard
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:
Somehow localhost is added in the url
@jedymatt Please do you still have an issue here?
@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
.