By Christopher Ambler on Monday, 20 September 2021
Likes 0
Views 756
Votes 0
Please find, below, some custom code that you guys helped provide a while back. Given the path to an image, this processes the image so it can be used as a post cover. As of this beta, this code is now breaking.

Specifically, this code is throwing an error:


// Read the external image file
$connector = EB::connector();


I suspect you've made a breaking change. Could you please advise?


public static function downloadImage(string $url, $post): ?stdClass
{
$config = EB::config();

if (!$config) {
return null;
}

// Store the image on a temporary location
$temporaryPath = JPATH_ROOT . '/tmp/' . md5($url);

// Read the external image file
$connector = EB::connector();
$connector->addUrl($url);
$connector->execute();

$contents = $connector->getResult($url);

// Save the image to a temporary location
JFile::write($temporaryPath, $contents);

// Prepare the image data
$file = getimagesize($temporaryPath);
$file['name'] = basename($url);
$file['tmp_name'] = $temporaryPath;
$file['type'] = $file['mime'];

$media = EB::mediamanager();
$uri = 'user:' . $post->created_by;

$adapter = $media->getAdapter($uri);
$result = $adapter->upload($file);

// Delete the temporary file
JFile::delete($temporaryPath);

if (!isset($result->type)) {
return null;
}

$path = $config->get('main_image_path');
$path = rtrim($path, '/');

$relative = $path . '/' . $post->created_by;

$relativeImagePath = $relative . '/' . $file['name'];
$result->html = '<img src="' . $relativeImagePath . '" />';

return $result;
}
Can you try update to this and see how it goes?

$connector = FH::connector($url);
$contents = $connector->execute()->getResult();
·
Tuesday, 21 September 2021 10:38
·
0 Likes
·
0 Votes
·
0 Comments
·
Using this new connector code has resolved the issue. The custom code works again. Thank you.
·
Wednesday, 22 September 2021 08:09
·
0 Likes
·
0 Votes
·
0 Comments
·
You are most welcome.

Just for your information, I have locked and marked this thread as resolved to avoid confusion in the future. Please start a new thread if you have any other issues in the future so it will be easier for us to manage your inquiries.

Thanks for understanding.
·
Wednesday, 22 September 2021 11:01
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post