Announcement

Collapse
No announcement yet.

Import images base on URL

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Import images base on URL

    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:

    PHP Code:
    public function parseImageUrl$url ) {
            
    $contents '';

            
    $curl curl_init($url);
            
    curl_setopt($curlCURLOPT_RETURNTRANSFERtrue );
            
    $ret_val curl_exec($curl);
            
    $contents =  chunk_split(base64_encode($ret_val));
            
    curl_close($curl);

            
    $exif exif_read_data($url0true);

            
    $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;
        } 
    and modification in parseValue() function. I have added the following code:
    PHP Code:
    if ($field == 'imageId') {
            
    $value $this->parseImageUrl($value);

    Note that is working for fieldname "image" and for Jpeg files only. Waiting for better solutions if you have. Thank you.
    Last edited by clevercode; 06-13-2017, 03:55 PM.
Working...
X