Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 2461 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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...
  • 3 years later...
Posted

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...
Posted

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" )

This topic is 2461 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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