I have a field that will accept an image link coming from the external source. But of course, to set that image I have to save it in Drupal first. I'm wondering how do Drupal save the image from an external link. I use the following code.
$imageUri = 'https://api.statvoo.com/favicon/?url=google.com'; // this is a favicon $file = File::create([ 'uri' => $imageUri, 'status' => 1, ]); $file->save(); $user_profile->field_profile_image = [ 'target_id' => $file->id(), 'alt' => 'Alt text', 'title' => 'Title', 'width' => 200, 'height' => 200, ]; $user_profile->save();
I notice that the following values and the external image URL were added in the image field, but the image is not displayed on the page. Thanks in advance!