Upload files to AWS S3

Hi guys

I have an on site implementation (Sugar Ent 10.0.3) and I have an external process on the CRON server that creates pdf files that I have to relate to Contact Records.
I'm planning to create a Job that gets the files from a particular directory in the server and use the current functionality that Sugar uses to upload file to AWS S3.
Could you help me to know which library or class I will able to use to solve this requirement?
Kind Regards, 
Pedro Bazan
  • Hello Pedro

    We deal with Amazon Services from Sugar by configuring the interaction with Logic Builder low-code tool
    Here is an example of how we configured "Put an attachment from the Note to S3 bucket" (a piece of flowchart)

    Is that configuring you are looking for?

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • Hi

    I haven't seen you for a while, good to have you back.

    While Dmytro's solution may very well be the fastest way to do this, it does require you purchasing the Logic Builder tool he is selling.

    I have not worked with AWS S3, but within the Sugar Framework, I have a snippet of code that still works but was developed back in 2012 and might need some updating... still, it may give some useful clues...

    This old code takes a file that a user uploaded in a web form and creates a record in a custom module called attch_CaseAttachments which is a "Documents" type module related to Cases. The file that was uploaded is stored in the upload directory specified in your SugarCRM's config file upload_dir:

    //HANDLE ANY ATTACHMENTS
    
    if(isset($_FILES['attachment']) && $_FILES['attachment']['error'] != '0'){
         $errMsg = string_format($GLOBALS['app_strings']['UPLOAD_ERROR_TEXT'],array($_FILES['attachment']['error'], self::$AttachmentError[$_FILES['attachment']['error']]));
         $GLOBALS['log']->debug("WebForm:: Attachment ERROR {$errMsg}");
         exit_with_message(true, $AttachmentError[$_FILES['attachment']['error']]);
    }elseif(isset($_FILES['attachment']) && $_FILES['attachment']['error'] == '0'){
         $uf = new UploadFile('attachment');
         if($uf->confirm_upload()){
            $GLOBALS['log']->debug("WebForm:: Processing Attachment:" . print_r($uf,true));
            $do_final_move = false;
            $a  = BeanFactory::newBean('attch_CaseAttachments');
            $doc_name = isset($input['attachmentName'])?$input['attachmentName']:$uf->stored_file_name;
            $a->filename = $doc_name;
            $a->document_name = $doc_name;
            $a->file_mime_type = $uf->mime_type;
            $a->category_id = 'incoming';
            $a->team_id = $team_id;
            $a->team_set_id = $team_set_id;
            $a->save();
            $attach_id = $a->id;
            $do_final_move = true;
            if ($do_final_move) $uf->final_move($attach_id);
        }else{
            $GLOBALS['log']->debug("WebForm:: Could not Process Attachment");
        }
    }
    $cs = BeanFactory::retrieveBean('Cases', $case_id, array('use_cache' => false));
    
    // link the case to the attachment 
    if (isset($attach_id) && $attach_id != ''){
       $GLOBALS['log']->debug("WebForm::[CASE:{$case_number}] Link Attachment to Case");
       $cs->load_relationship('attch_caseattachments_cases');
       $cs->attch_caseattachments_cases->add($attach_id);
    }
    

    See if it helps :)

    FrancescaS

  • Sugar has the AWS S3 libraries available in the vendor directory. You don't need to install anything. There is an old article from http://cheleguanaco.blogspot.com/2015/05/sugarcrm-customization-custom-upload.html which discusses using S3, 

    Check this file <sugarcrm>/include/SugarUploadS3.php and <sugarcrm>/vendor/aws/aws-sdk-php for more hints

  • Hi Francesca,

    Yes, I do promote the Logic Builder - a cloud tool https://logicbuilder.integroscrm.com 

    For the annual Logic Builder subscription cost for the company, which amount is less than 3 days of Professional IT Services according to the regular US/UK/EU rates, it enables deep Sugar platform capabilities and rapid Sugar configuring of numerous customer tasks for techies of Sugar admin-level - those, who usually cover the gaps to unique company demands with Studio, SugarBPM, Advanced Reporting and sometimes forced to build crazy unary operation formulas for calc fields

    Regardin AWS topic - most of AWS services are reachable via the low-code tool - not just S3 bucket, but also Rekognition, Comprehend, Transcribe, etc letting the platform do the work in interests of Sugar subscribers

    Please note - any of the configurations performed are installable via Module Loader and do not demand access to Logic Builder environment to operate

    And there is neither fee nor bank card needed for the trial

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • Hi Dmytro,

    Your tool may certainly be good value for those who do not wish to deal with code-level changes, but, in my opinion, most of the people who post questions on the DevClub side of the SugarClub are used to working in code and are looking for code-level solutions.

    I did not mean to discount your work or your product, I was just pointing out that the tool you describe does not come with Sugar and will require a purchase. I am not sure that is always clear in your posts.

    My apologies if my comment offended you.

  • Francesca,

    on a contrary, I much appreciate these discussions and your involvement!

    As I see from the SugarClub posts and DevClub posts specifically, a lot of people - admins, consultants,- post questions here because they still think their types of tasks should be addressed with code development only, maybe hoping to achieve results with some code adjustments performed themselves with guidance by experienced developers.

    I'm just trying to show another option - along with many Sugar platform advantages, the low-code / no-code configuring is available for solving their tasks with no deep-diving into code development - just design logic and get the ready-to-install zip package

    I've heard a lot of times if a low-code tool would be in Sugar, but it does not - and the additional cost may be reasonable.

    I hope this makes sense

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • Point taken. Variety does make things more interesting. :)

  • From that link I get
    ''Sorry, the page you were looking for in this blog does not exist.''

    CRM Business Consultant

  • Hi Vincent,
    I wonder would it be preferable for non-developers to configure Sugar with no-code rather than to adjust PHP code - if there is such a possibility, wouldn't it?

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • hi Jeff, I noticed after your link has a comma at the end hence why I was getting not found
    cheleguanaco.blogspot.com/.../sugarcrm-customization-custom-upload.html

    CRM Business Consultant