Hello,
It will be nice having this feature in core application. I have made this approach for anyone who wants to import images (tested for version 4.7.1):
Modifications in : /application/Espo/Services/Import.php
Added the following function:
and modification in parseValue() function. I have added the following code:
Note that is working for fieldname "image" and for Jpeg files only. Waiting for better solutions if you have. Thank you.
It will be nice having this feature in core application. I have made this approach for anyone who wants to import images (tested for version 4.7.1):
Modifications in : /application/Espo/Services/Import.php
Added the following function:
PHP Code:
public function parseImageUrl( $url ) {
$contents = '';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
$ret_val = curl_exec($curl);
$contents = chunk_split(base64_encode($ret_val));
curl_close($curl);
$exif = exif_read_data($url, 0, true);
$contents = base64_decode($contents);
$attachment = $this->getEntityManager()->getEntity('Attachment');
$attachment->set("name", $exif["FILE"]["FileName"]);
$attachment->set("type", $exif["FILE"]["MimeType"]);
$attachment->set("size", $exif["FILE"]["FileSize"]);
$attachment->set("role", "Attachment");
$attachment->set("related_type", "Product");
$this->getEntityManager()->saveEntity($attachment);
$this->getFileStorageManager()->putContents($attachment, $contents);
return $attachment->id;
}
PHP Code:
if ($field == 'imageId') {
$value = $this->parseImageUrl($value);
}
Comment