Announcement

Collapse
No announcement yet.

Naming uploading files

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

  • Naming uploading files

    Greetings!
    Could you help me with topic? I've made search through forum and didn't find answer. How is the naming of uploading files happens and where can I change path to upload folder?
    The issue is that I want to add my own prefix in the name of uploaded image, for example number of object, which I'm storing in field in object, so the name of the file would be for example "23_filename".

  • #2
    ОК, I've found the file /application/Espo/EntryPoints/Image.php where at least naming of the thumbs happening.
    Into that file
    Code:
     protected function show($id, $size) { ....  
     $sourceId = $attachment->getSourceId(); ...  
     if (!empty($size)) {     $fileName = $sourceId . '_' . $size . '.jpg'; } else {     $fileName = $attachment->get('name'); }  ... }
    How can I appeal to entity field from here? In my case I need to pull out RealEstateProperty field, in entity where attachment of files goes, for example "Floor Count" or my custom field.
    Last edited by Makov; 06-30-2016, 10:01 AM.

    Comment


    • #3
      Maybe here application/Espo/Repositories/Attachment.php

      Comment


      • Makov
        Makov commented
        Editing a comment
        OK, thanks, could you show how to appeal to entity fields from that files?
        I'm trying to get it like that

        $realprop = $this->getEntityManager()->getEntity('RealEstateProperty', $id);
        $number = $realprop->get('number');


        and it throws Fatal error: Call to a member function get() on a non-object

    • #4
      Made it that way
      application/Espo/EntryPoints/Image.php
      Code:
      ... 
       protected function show($id, $size) { ...    
       $propId = $attachment->get('parentId'); $realprop = $this->getEntityManager()->getEntity('RealEstateProperty', $propId); $realNumber = $realprop->get('number'); ....    
       if (!empty($size)) {     if (!empty($this->imageSizes[$size])) {         $thumbFilePath = "data/upload/thumbs/{$realNumber}/{$sourceId}_{$size}"; ...
      It works perfectly for thumbs, every image in separate folder with number of object, working on original file.

      Comment


      • #5
        In file application/Espo/Controllers/Attachment.php
        Code:
         
         $this->getContainer()->get('fileManager')->putContents('data/upload/' . $attachment->id, $contents);
        Is "parentId" exist at this moment? Does attachment have it at that point?
        Any possibility to access it from that file?
        Task is the same - make separate folders for upload.

        Comment


        • #6
          Could anybody help? I need to appeal to parent id of enity "Attachment", to detect her parent at the moment of her creation. How it could be done?

          Comment


          • #7
            At this moment parentId is not available. Because it get uploaded first and then get linked with parent.
            Last edited by yuri; 07-04-2016, 08:11 AM.

            Comment


            • #8
              Thank you!

              Comment

              Working...
              X