eZ Community » Forums » Developer » Set image in php
expandshrink

Set image in php

Set image in php

Tuesday 21 November 2017 4:43:51 pm - 2 replies

I am on a command that saves images in image fields.

 $objectDraft = $this->contentService->createContentDraft($content->contentInfo);
$objectUpdateStruct = $this->contentService->newContentUpdateStruct();
$objectUpdateStruct->setField('image', '/tmp/image.jpg');
$objectDraft = $this->contentService->updateContent(
  $objectDraft->versionInfo,
  $objectUpdateStruct
);
$this->contentService->publishVersion($objectDraft->versionInfo);

The information seems well recorded.
But no img in the BO ...

   'id' => '2/6/6/4/4662-24-fre-FR/fa6f2a0e26769bde60eee426a19cf06e.jpg',
  'alternativeText' => '',
  'fileName' => 'fa6f2a0e26769bde60eee426a19cf06e.jpg',
  'fileSize' => 15898,
  'uri' => '/var/client/storage/images/2/6/6/4/4662-24-fre-FR/fa6f2a0e26769bde60eee426a19cf06e.jpg',
  'imageId' => '594-4662',
  'inputUri' => NULL,
  'width' => '300',
  'height' => '613',

Tuesday 21 November 2017 4:46:20 pm

I also tested this technique:

 

 $filePath = '/tmp/image.jpg';
/** @var \eZ\Publish\Core\FieldType\Image\Value $imageValue */
$imageValue = $content->getFieldValue('image');
$imageValue->inputUri = $filePath;
$imageValue->alternativeText = '';
$imageValue->id = $filePath;
$objectUpdateStruct->setField('image', $imageValue);

Modified on Tuesday 21 November 2017 4:47:39 pm by Rémy PHP

Tuesday 21 November 2017 4:49:02 pm

Community Project 2014.11

http://share.ez.no/forums/developer/public-api-updating-image-fields

https://doc.ez.no/display/EZP/The+Image+FieldType

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from