Class S3UploadAction

  • All Implemented Interfaces:
    java.lang.Comparable<S3UploadAction>

    public class S3UploadAction
    extends io.inversion.Action<S3UploadAction>
    Sends browser multi-part file uploads to a defined S3 location

    Bean property config can be set directly on the handler in your inversion.properties files but you should really consider this to be a service singleton where the properties can be passed in via Action config allowing a single handler instance to upload files to multiple buckets based on request path.

    So instead of config-ing something like

    handler.dynamicBasePath=yyyy/MM/dd or handler.bucket=somebucket

    do this

    action.config=dynamicBasePath=yyyy/MM/dd@amp;bucket=somebucket

    While accessKey/secreKey/awsRegion CAN be set either on the Handler or on the Action in this way, if you control the host environment and are uploading everyting to your own AWS account, you should consider using IAM roles to authenticate. Than way you don't need to config the credentials at all.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class io.inversion.Rule

        io.inversion.Rule.RuleMatcher
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String allowedCharactersRegex  
      protected long maxUploadLength  
      protected java.lang.String s3AccessKey  
      protected java.lang.String s3AwsRegion  
      protected java.lang.String s3BasePath  
      protected java.lang.String s3Bucket  
      protected com.amazonaws.services.s3.AmazonS3 s3Client  
      protected java.lang.String s3DatePath  
      protected java.lang.String s3SecretKey  
      • Fields inherited from class io.inversion.Rule

        ALL_METHODS, configMap, description, excludeMatchers, excludeOn, includeMatchers, includeOn, log, name, order, params
    • Constructor Summary

      Constructors 
      Constructor Description
      S3UploadAction()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String byteToHexString​(byte[] input)  
      com.amazonaws.services.s3.AmazonS3 getS3Client()  
      protected boolean isValidPath​(io.inversion.utils.Path path)  
      protected void onFileUploaded​(io.inversion.Request req, io.inversion.Response resp, io.inversion.Upload upload, io.inversion.s3.S3UploadAction.S3File file)  
      void run​(io.inversion.Request req, io.inversion.Response res)  
      protected io.inversion.s3.S3UploadAction.S3File saveFile​(io.inversion.Request req, io.inversion.Upload upload)  
      protected io.inversion.s3.S3UploadAction.S3File uploadFile​(java.lang.String bucket, java.lang.String key, java.io.InputStream in, long size)  
      protected io.inversion.s3.S3UploadAction.S3File uploadFile​(java.lang.String bucket, java.lang.String key, java.io.InputStream in, long size, java.util.Map<java.lang.String,​java.lang.String> metadataProps, java.util.Map<java.lang.String,​java.lang.String> tags)  
      S3UploadAction withS3Client​(com.amazonaws.services.s3.AmazonS3 s3Client)  
      • Methods inherited from class io.inversion.Action

        configureOp, doDelete, doGet, doPatch, doPost, doPut, getFullIncludePaths, getIncludePaths, isDecoration, joinPaths, joinPaths0, run0, withDecoration
      • Methods inherited from class io.inversion.Rule

        afterWiringComplete, checkLazyConfig, compareTo, doLazyConfig, getAllExcludePaths, getAllIncludeMethods, getAllIncludePaths, getDefaultIncludeMatchers, getDescription, getExcludeMatchers, getIncludeMatchers, getName, getOrder, getParams, match, match, matches, matches, toString, withDescription, withExcludeOn, withExcludeOn, withIncludeOn, withIncludeOn, withName, withOrder, withParam, withParams
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • s3AccessKey

        protected java.lang.String s3AccessKey
      • s3SecretKey

        protected java.lang.String s3SecretKey
      • s3AwsRegion

        protected java.lang.String s3AwsRegion
      • s3Bucket

        protected java.lang.String s3Bucket
      • s3BasePath

        protected java.lang.String s3BasePath
      • s3DatePath

        protected java.lang.String s3DatePath
      • maxUploadLength

        protected long maxUploadLength
      • s3Client

        protected com.amazonaws.services.s3.AmazonS3 s3Client
      • allowedCharactersRegex

        protected java.lang.String allowedCharactersRegex
    • Constructor Detail

      • S3UploadAction

        public S3UploadAction()
    • Method Detail

      • run

        public void run​(io.inversion.Request req,
                        io.inversion.Response res)
                 throws io.inversion.ApiException
        Overrides:
        run in class io.inversion.Action<S3UploadAction>
        Throws:
        io.inversion.ApiException
      • onFileUploaded

        protected void onFileUploaded​(io.inversion.Request req,
                                      io.inversion.Response resp,
                                      io.inversion.Upload upload,
                                      io.inversion.s3.S3UploadAction.S3File file)
      • saveFile

        protected io.inversion.s3.S3UploadAction.S3File saveFile​(io.inversion.Request req,
                                                                 io.inversion.Upload upload)
                                                          throws io.inversion.ApiException
        Throws:
        io.inversion.ApiException
      • uploadFile

        protected io.inversion.s3.S3UploadAction.S3File uploadFile​(java.lang.String bucket,
                                                                   java.lang.String key,
                                                                   java.io.InputStream in,
                                                                   long size)
                                                            throws io.inversion.ApiException
        Throws:
        io.inversion.ApiException
      • uploadFile

        protected io.inversion.s3.S3UploadAction.S3File uploadFile​(java.lang.String bucket,
                                                                   java.lang.String key,
                                                                   java.io.InputStream in,
                                                                   long size,
                                                                   java.util.Map<java.lang.String,​java.lang.String> metadataProps,
                                                                   java.util.Map<java.lang.String,​java.lang.String> tags)
                                                            throws io.inversion.ApiException
        Throws:
        io.inversion.ApiException
      • byteToHexString

        public java.lang.String byteToHexString​(byte[] input)
      • isValidPath

        protected boolean isValidPath​(io.inversion.utils.Path path)
      • getS3Client

        public com.amazonaws.services.s3.AmazonS3 getS3Client()
      • withS3Client

        public S3UploadAction withS3Client​(com.amazonaws.services.s3.AmazonS3 s3Client)