Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

aws lambda upload file to s3 java

try{
            // Create new file
            Util._logger.log(" Creating file transfer ");

            StringBuilder stringBuilder = new StringBuilder();

            //Writing in file
            stringBuilder.append('Data you want to write in file');

            // Upload file
            ByteArrayInputStream inputStream = new ByteArrayInputStream(stringBuilder.toString().getBytes(Constants.UTF_8));
            s3Client.putObject(dstBucket, uploadFileName, inputStream, new ObjectMetadata());

        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, " +
                    "which means your request made it " + 
                    "to Amazon S3, but was rejected with an error " +
                    "response for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
            Util._logger.log(Constants.EXCEPTION_ERROR + ase.getMessage());
            ase.printStackTrace();
        } catch (AmazonClientException ace) {
                System.out.println("Caught an AmazonClientException, " +
                        "which means the client encountered " +
                        "an internal error while trying to " +
                        " communicate with S3, " +
                        "such as not being able to access the network.");
                System.out.println(Constants.EXCEPTION_ERROR + ace.getMessage());
                Util._logger.log(Constants.EXCEPTION_ERROR + ace.getMessage());
                ace.printStackTrace();
        } catch (Exception e) {
                Util._logger.log(Constants.EXCEPTION_ERROR + e.getMessage());
                e.printStackTrace();
        }
Comment

PREVIOUS NEXT
Code Example
Java :: check if item lore is something bukkit 
Java :: convert text file into binnary format bitmap using java 
Java :: clear array in java 
Java :: How to disable special characters on keyboard in android 
Java :: java get parent process name 
Java :: Example of "this" : to invoke current class method 
Java :: play default message ringtone android studio 
Java :: amstrong 
Java :: bukkit java get max players 
Java :: default constructor java 
Java :: scrollbar in textarea java 
Java :: java optional parameters 
Java :: arraylist add method 
Java :: generic array creation java 
Java :: arduino convert byte array to string 
Java :: how to call a void method from another class in java 
Java :: java deserialize json object 
Java :: java hello world program 
Java :: get the logged in user java 
Java :: input 3 int 1 line in java 
Java :: rest api client url not connecting to the database in spring boot 
Java :: java.lang.NoClassDefFoundError: net/sf/cb2xml/def/IItem 
Sql :: mysql workbench turn off safe mode 
Sql :: postgresql update sequence next value 
Sql :: . ERROR! The server quit without updating PID file (/usr/local/var/mysql/MacBook-Pro-de-Quentin.local.pid). 
Sql :: grant revoke privileges to mysql username 
Sql :: postgresql add enum value 
Sql :: sql drop procedure if exists 
Sql :: how to install psql in ubuntu 
Sql :: sql query to make a existing column auto increment 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =