Copy received files to Google Drive

Discussion in 'ActionScripts' started by David, Oct 1, 2019.

  1. David

    David Administrator
    Staff Member

    Dec 1, 2015
    Likes Received:
    This example describes how to use User delivery Action Script together with Gdrive tool to copy files from a received message for a specified user.

    1) Gdrive tool installation
    Log in to the LF console as root, download latest gdrive for 64bit linux platform and save in to the /usr/loca/bin folder.
    curl -L -o /usr/local/bin/gdrive
    cd /usr/local/bin
    chmod +x gdrive

    2) Authentication with your google drive account (important)
    Run the gdrive tool from the shell as "_actionscript" user and open the URL the tool will display in a browser.
    Finally paste the returned unique code back in the cmd line.
    sudo -u _actionscript /usr/local/bin/gdrive list
    Authentication needed
    Go to the following url in your browser:
    Enter verification code: a/b/c/d/1/2/3/....

    3) Action Script
    Create your Action script named i.e. "copy_to_gdrive.rb" in "Admin > Configuration > Action Scripts > Add" settings.
    #!/usr/bin/env ruby
    require 'json'
    #read message data
    message_data = JSON.parse([0]))
    #parse attachments
    message_data["message"]["attachments"].map {
    |a| file=a["system_file"] 
    #copy files one by one to gdrive
    result=%x{ /usr/local/bin/gdrive upload "#{file}" }
    #log details to the activity logs
    %x{ logger -p -t copy_to_gdrive "#{result}" }

    4) Script Assignment
    Assign that script to the required user with the "Action" switch in the profile in "Admin > Users > Edit".

    5) Testing

    Log in as some another user and send a Secure message with test files to the user with the script.
    After a while after the message is received the files should appear in the gdrive.
    Sam-72891 likes this.

Share This Page