Change file storage location

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zoltar
    Junior Member
    • Nov 2023
    • 6

    Change file storage location

    Hello,


    Is it possible to change location for KB & Document uploads?

    Any time you upload a file or picture I'd like to direct these to a specific drive\storage array.

    I see some of it is stored in "/data/upload"

    I found this in the Config file, but changing it doesn't seem to do anything:

    'defaultFileStorage' => 'EspoUploadDir'


    With appreciation,
    Justin
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    You need to implement a custom storage check this out https://docs.espocrm.com/development...-file-storage/
    Rabii
    Web Dev

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1250

      #3
      Here is how you can do it in an upgrade safe way:

      1 - create custom/Espo/Custom/Resourcs/metadata/app/fileStorage.json
      PHP Code:
      {
          "implementationClassNameMap": {
               "EspoUploadDir": "\\Espo\\Custom\\Core\\FileStorage\\Storages\\EspoUploadDir"    
          }
      }

      2 - create custom/Espo/Custom/Core/FileStrage/Storages/EspoUploadDir.php
      PHP Code:
      <?php
      
      namespace Espo\Custom\Core\FileStorage\Storages;
      
      use \Espo\Entities\Attachment;
      use \Espo\Core\Exceptions\Error;
      
      class EspoUploadDir extends Espo\Core\FileStorage\Storages\EspoUploadDir
      {
          protected function getFilePath(Attachment $attachment)
          {
              $sourceId = $attachment->getSourceId();
              return 'crm/storageunit/' . $sourceId; // HERE YOUR CUSTOM PATH
          }
      }
      I hope this helps
      Rabii
      Web Dev

      Comment

      Working...