Announcement

Collapse
No announcement yet.

Relocating the upload folder - Urgent Problem

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

  • Relocating the upload folder - Urgent Problem

    We have been using ESPO for a year now. We receive a lot of emails into the CRM which carry numerous attachments. In ESPO the attachments are loaded into the data->upload folder. Currently, the size of this folder has bloated to 17GB of space. The company logos and signatures are the biggest valueless culprits. Some of these can be of 2MB size each. In our environment, we have an apps server and a database server all are cloud-hosted. We can relocate the ESPO database to the DB Server but we are not sure how to relocate the upload folder. We need to do this as the the upload folder is eating up the disk space on the apps server and causing the ESPO system to halt.

    How do we relocate the upload folder to another server or drive? Assistance is needed urgently. Thank you in advance.

  • #2
    You can specify custom file storage implementation https://github.com/espocrm/espocrm/b...torage.json#L3

    Create custom/Espo/Custom/Resourcs/metadata/app/fileStrage.json

    Code:
    {
        "implementationClassNameMap": {
             "EspoUploadDir": "\\Espo\\Custom\\Core\\FileStorage\\Storages\\EspoUploadDir"    
        }
    }

    Create a file 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 
    'data/upload/' $sourceId// HERE YOUR CUSTOM PATH
        
    }
    }

    Clear cache.

    Note, that I didn't test this, there can be mistakes.

    Comment


    • #3
      How to use this to have different folders for email, user avatars, images in real estate and others?

      Comment


      • #4
        The developers should incorporate a separate Administration function to define the paths and folders for the various storage. Currently most of the data are stored in the core apps directory (e.g upload). Its takes ages to backup the core folder due the upload folder. We accumulated around 20GB of graphics in there due to the inline images in the emails and mobile phone capture attachments. The are wasteful asset killers. Also when cleanup jobs take up hours when we delete these files using the Admin function "Attachments".

        Comment


        • #5
          Originally posted by yurikuzn View Post
          You can specify custom file storage implementation https://github.com/espocrm/espocrm/b...torage.json#L3

          Create custom/Espo/Custom/Resourcs/metadata/app/fileStrage.json

          Code:
          {
          "implementationClassNameMap": {
          "EspoUploadDir": "\\Espo\\Custom\\Core\\FileStorage\\Storages\\EspoUploadDir"
          }
          }

          Create a file 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 
          'data/upload/' $sourceId// HERE YOUR CUSTOM PATH
          }
          }

          Clear cache.

          Note, that I didn't test this, there can be mistakes.

          Hi Yuri,

          The code works perfectly. Done it already. Thank you so much.


          **** COVID-99 TAG LINE : WE ARE PROUD THAT WE ARE MALAYSIANS *******
          In Malaysia, we have achieved single digit new cases and zero deaths per day for
          last one month. Of the 8,600 infections we have only 600 cases left for treatment
          and remainder have all gone home!! You can do it too. Listen to your government!!!
          ************************ Stay Free and Stay Safe *****************************************
          Last edited by murugappan; 06-19-2020, 03:05 PM.

          Comment


          • #6
            Hi,
            I try to implement this, but it does not work here.
            Error log:

            Code:
            Espo.ERROR: (500) InjectableFactory: Class '\custom\Espo\Custom\Core\FileStorage\Storages\EspoUploadDir' does not exist.

            Comment


            • telecastg
              telecastg commented
              Editing a comment
              Double check the name of your custom php script and path to make sure that it matches the namespace and class name. The error message is saying that the system can not find the script or the class.

              Noticed that there is a typo in the example code, the script name is "custom/Espo/Custom/Core/FileStrage/Storages/EspoUploadDir.php" but should be "custom/Espo/Custom/Core/FileStorage/Storages/EspoUploadDir.php". Not sure if this is relevant, but if you named your script exactly as the example code that could explain why the system can't find it.
              Last edited by telecastg; 12-13-2020, 08:02 AM.

            • murugappan
              murugappan commented
              Editing a comment
              Hi telecastg, when i tested in our instance i corrected the name mistake. The only setback i had was that, although the documents got stored in a different folder, the thumbnails stayed where they were. Sort of worked and didnt work. hehehe... I decided leave things as they were for security and control reasons, mainly control reasons as follows:

              (1) Did not want to alter the original code and structure to avoid any upgrade issues later
              (2) Existing structure works well as when we backup, both the documents and core system are done together. This works well when restoring.

              With regards to Shalmaxb's problem, i had something similar (not sure if the same) and it was because i forgot the namespace definition and use parameters. Perhaps, should check if overlooked.

          • #7
            Does it work correctly in new version?
            I have following problem:

            [2021-12-21 09:32:43] ERROR: Slim Application Error Type: Error Code: 0 Message: Class 'Espo\Custom\Core\FileStorage\Storages\Espo\Core\F ileStorage\Storages\EspoUploadDir' not found File: /var/www/html/crm.gridnet.pl/public_html/custom/Espo/Custom/Core/FileStorage/Storages/EspoUploadDir.php Line: 8 Trace: #0

            Comment


            • #8
              This works for me in 7.0.4

              custom/Espo/Custom/Resourcs/metadata/app/fileStorage.json
              Code:
              {
              "implementationClassNameMap": {
              "EspoUploadDir": "\\Espo\\Custom\\Core\\FileStorage\\Storages\\EspoUploadDir"
              }
              }
              custom/Espo/Custom/Core/FileStrage/Storages/EspoUploadDir.php
              PHP Code:
              <?php

              namespace Espo\Custom\Core\FileStorage\Storages;

              use 
              \Espo\Core\FileStorage\Attachment;
              use 
              \Espo\Core\Exceptions\Error;

              class 
              EspoUploadDir extends \Espo\Core\FileStorage\Storages\EspoUploadDir
              {
              protected function 
              getFilePath(Attachment $attachment)
              {
              $sourceId $attachment->getSourceId();
              return 
              '/mnt/CRMstorage/upload/' $sourceId;
              }
              }
              Last edited by Piotr Wójtowicz - GRIDNET; 12-21-2021, 01:45 PM.

              Comment

              Working...
              X