Help with image field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1476

    Help with image field

    Hello,

    I need to write a job who "curl get http://covers.openlibrary.org/b/isbn/9782709626064-M.jpg"
    So how i can save this image with code so espoCRM do thumbs as he do on front-end when we upload a image.

    Regards
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    #2
    Hi item , not sure how to incorporate this functionality to your curl retrieval of an external image, but this is the code that handles uploading attachments (images) to an entity in the front-end when a User clicks the "paper clip" icon on an entity's detail form:



    Hopefully that can give you some ideas.

    Comment

    • item
      Active Community Member
      • Mar 2017
      • 1476

      #3
      Hello telecastg, i am so : "always near goal" .. but .. and just you send some info and "we can do it"

      for some need post file on stream :
      first need create Note.. the create Attachment with NoteID

      PHP Code:
      <?php 
      private function createNote($contactId, $userName, $filePath, $fileName)
      {
      $entityManager = $this->getEntityManager();
      $note = $entityManager->getEntity('Note');
      $note->set(array(
      'deleted' => 0,
      'post' => $fileName ." @" .$userName,
      'data' => '{}',
      'type' => 'Post',
      'target_type' => null,
      'isGlobal' => 0,
      'isInternal' => 0,
      'parentId' => $contactId ,
      'parentType' => 'Contact',
      'relatedId' => null,
      'relatedType' => null,
      'createdById' => null,
      'superParentId' => null,
      'superParentType' => null,
      ));
      $noteId = $entityManager->saveEntity($note);
      $attachment = $entityManager->getEntity('Attachment');
      $attachment->set(array(
      'name' => $fileName,
      'deleted' => 0,
      'type' => mime_content_type($filePath),
      'size' => filesize($filePath),
      'source_id' => null,
      'field' => 'attachments',
      'role' => 'Attachment',
      'storage' => null,
      'storage_file_path' => null,
      'global' => 0,
      'parentId' => $noteId,
      'parentType' => 'Note',
      'relatedId' => null,
      'relatedType' => null,
      'createdById' => 'system',
      ));
      $attachmentId = $entityManager->saveEntity($attachment);
      exec("mv " .$filePath . " " . getcwd() ."/data/upload/" .$attachmentId);
      //$GLOBALS['log']->info( "noteId=" .$noteId ." - attachmentId=" .$attachmentId ." - contactId=" .$contactId );
      }
      ?>
      image field send by front-end url : application/Espo/EntryPoints/image.php

      So i just need, curl, create a attachment, and then use with some function in application/Espo/EntryPoints/image.php

      Thanks man




      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment


      • telecastg
        telecastg commented
        Editing a comment
        You're very welcome, thanks for posting your implementation :-)
    • item
      Active Community Member
      • Mar 2017
      • 1476

      #4
      Hello telecastg
      i have a issue in front-end

      book entity -> controller -> service

      in service i do this :
      $entity->set('pictureId', $attachment->id);
      $em->saveEntity($entity); <--- i save picture in services

      return $data;

      in client/custom/src/views/book/detail.js

      PHP Code:
      var self = this;
      $.ajax({
      url: 'Book/action/GetInfo',
      type: 'POST',
      data: JSON.stringify(data),
      success: function (data) {
      if (data['status']){
      self.model.set('publisher', data['publisher']);
      self.model.set('publishedDate', data['publishedDate']);
      self.model.set('description', data['description']);
      self.model.set('author', data['author']);
      self.model.set('pageCount', data['pageCount']);
      self.model.set('snippet', data['snippet']);
      
      Espo.Ui.notify( data['status'] + ' ' + data['message'] , 'success', 2000);
      
      }else{
      Espo.Ui.notify( data['status'] + ' ' + data['message'] , 'error', 2000);
      }
      }
      }); 
      
      so my field "picture" is changed by back-end.. how i can refresh front-end ? so picture is visible without "F5 ou refresh browser" ?

      Thanks

      And another f*cking issue :

      i get book info from google book api as json
      but i have this in response : & # 39 ; and so (i have put space here between char .. else is ' )
      how do you clean & # 39 ; => single quote and save in database








      Last edited by item; 10-19-2020, 09:06 PM.
      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      • telecastg
        Active Community Member
        • Jun 2018
        • 907

        #5
        Hello item

        In regards to the model update, try
        Code:
        self.reRender();
        as part of the successful Ajax response.

        In regards to the second question I don't know but here's a link to a post that discusses the issue of single quotes inside json https://stackoverflow.com/questions/...-single-quotes hopefully that can help

        Comment


        • item
          item commented
          Editing a comment
          @telecastg

          self.model.fetch() : worked

          second : no.. it's on backend the value is so :

          "searchInfo": {
          "textSnippet": "Un livre à la fois sérieux et plein d&#39;humour pour aider les parents à garder le cap dans la tourmente de l&#39;adolescence de leurs enfants."
          }

          As you see, i $entity->set('snippet' , $textSnippet); .. and the f*cking &#39; kill the text in field
      • telecastg
        Active Community Member
        • Jun 2018
        • 907

        #6
        I would try to use regex to filter and replace &#39 with another character like "tick" that is used in sql commands, before passing it as a variable to the entity.

        I don't have any regex skills but this link in StackOverflow talks about the issue and how to solve it in PHP https://stackoverflow.com/questions/...in-php/3903230 maybe that can help.
        Last edited by telecastg; 10-21-2020, 12:16 AM.

        Comment

        Working...