Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Scriptmaster + Grails + Amazon S3

Featured Replies

Hi all,

I'm beginning to delve into Scriptmaster and I'm curious if it can use any of the grails functionality? I know 360works released their SafetyNet plugin, but I'm curious if I could script my (non-server based) solution to upload a ZIP file to S3 using ScriptMaster.

Has anyone tried this kind of functionality?

Cheers,

Denis

  • 2 weeks later...

I have not used Grails but I believe you should be able to use it, you can add the necessary jars by adding them to the jars table.

  • 3 years later...

Hi Dennis,

I know this question is from many years ago but I'm trying to do the same thing with no luck so far. Were you able to get Scriptmaster to do the job? Thanks!

jared

  • 4 years later...

Here's a good a place as any to post some S3 scriptmaster functions I recently knocked up. You have to import a small number of JARs from the jets3t framework http://www.jets3t.org (or I compiled a fat JAR to do it in one SMLoadJar step) to satisfy the imports and dependencies. And they definitely could do with some polish and better error handling, but they just about get the basic jobs done. (awsList, awsUpload, awsUploadContainer, awsDownload)

awsList will list buckets if you leave bucketName blank

 

RegisterGroovy( "awsList( myAccessKeyID;  mySecretKey; bucketName; objectPrefix)" ;

"import org.jets3t.service.impl.rest.httpclient.RestS3Service;¶
import org.jets3t.service.security.AWSCredentials;¶
import org.jets3t.service.model.*;¶

try {¶
    def s3 = new RestS3Service( new AWSCredentials( myAccessKeyID, mySecretKey ) );¶
    def objectListString=\"\";¶
    if (bucketName)¶
    {    // def bucket = s3.getBucket( bucketName);¶
        def chunk=s3.listObjectsChunked(bucketName, objectPrefix, \"/\", 8L, \"\", true);¶
        def objectList=chunk.getObjects();¶
        objectListString+= chunk.getCommonPrefixes().join(\"\n\");¶
        for (int o = 1; o < objectList.length; o++) {¶
            objectListString+= \"\n\" + objectList[o].getKey() + \" [\" + objectList[o].getContentLength() + \" bytes]\";¶
        }¶
    }¶
    else¶
    {    def bucketList = s3.listAllBuckets();¶
        for (int o = 0; o < bucketList.length; o++) {¶
            objectListString+= bucketList[o].name + \"\n\";¶
        }¶
    }¶
    return objectListString.replaceAll(/(?m)^${objectPrefix}/, \"\");¶

catch(Exception e) { return e;}¶
return false;¶"; "isGui=false" )

 

+ RegisterGroovy( "awsUpload( myAccessKeyID;  mySecretKey ; bucketName; prefixKey ; pathToFile)" ;

"import org.jets3t.service.impl.rest.httpclient.RestS3Service;¶
import org.jets3t.service.security.AWSCredentials;¶
import org.jets3t.service.model.*;¶

try {¶
def s3 = new RestS3Service( new AWSCredentials( myAccessKeyID, mySecretKey ) );¶
s3uploaditem= new S3Object( new File( pathToFile ) );¶
s3uploaditem.setKey(prefixKey + s3uploaditem.getKey());¶
def s3objStore = s3.putObject( bucketName  , s3uploaditem );¶
return true; // or parse data from s3objStore¶

catch(Exception e) { return    e;}¶
return false;¶"; "isGui=false" )

 

+RegisterGroovy( "awsUploadContainer( myAccessKeyID;  mySecretKey ; bucketName; prefix ; containerField)" ;

"import org.jets3t.service.impl.rest.httpclient.RestS3Service;¶
import org.jets3t.service.security.AWSCredentials;¶
import org.jets3t.service.model.*;¶

try {¶
def s3 = new RestS3Service( new AWSCredentials( myAccessKeyID, mySecretKey ) );¶
s3uploaditem= new S3Object( prefix, fmpro.getContainerStream( containerField ).getBytes()  );¶
def s3objStore = s3.putObject( bucketName , s3uploaditem );¶
return true; // or parse data from s3objStore¶

catch(Exception e) { return e;}¶
return false;¶"; "isGui=false" )

 

+ RegisterGroovy( "awsDownload( myAccessKeyID;  mySecretKey ; bucketName; myBucketPath ; pathToFile)" ;

"import org.jets3t.service.impl.rest.httpclient.RestS3Service;¶
import org.jets3t.service.security.AWSCredentials;¶
import org.jets3t.service.model.*;¶
import org.jets3t.service.utils.*;¶
import java.io.FileOutputStream;¶

try {¶
def s3 = new RestS3Service( new AWSCredentials( myAccessKeyID, mySecretKey ) );¶
def s3obj = s3.getObject( bucketName, myBucketPath);¶
downloadFile = new File(pathToFile);¶
if(downloadFile.isDirectory()) { downloadFile = new File(pathToFile + \"/\" + myBucketPath.substring(myBucketPath.lastIndexOf(\"/\") + 1 )   ) }¶
input = s3obj.getDataInputStream();¶
output = new FileOutputStream(downloadFile);
int bytesRead; byte[] buffer = new byte[8 * 1024];¶
while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); }¶
output.flush();¶
return true;¶

catch(Exception e) { return e;}¶
return false;¶"; "isGui=false" )

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.