Skip to content
/ jaide-s3 Public

A very simple Java wrapper around the Amazon S3 library. One-line-of-code uploading of files to Amazon S3. Use Spring or don't. Zero configuration. Requires Maven for building. Easy to integrate into any Java project.

License

Notifications You must be signed in to change notification settings

JAIDE/jaide-s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

This is a very simple wrapper around the Amazon S3 library. With this code you may:

  • Easily upload/delete files to/from Amazon S3 with two lines of code... and one of those two lines is the import-package line at the top of your .java file :-)
  • Make use of Spring as the library is Spring-enabled - but it's not a must. You're free to use the direct uploader OR the Spring service, whatever you prefer.
  • You can now (version 1.1) specify the content type of the uploaded file

Directly uploading a file

Here's how to upload a file without using Spring (if you're making use of the Apache commons-io library):

import de.jaide.s3.JaideS3Uploader;
...
new JaideS3Uploader("MyS3AccessKey", "MyS3SecretKey", "my-s3-bucket-name").upload("my-file-path", "my-filename.ext",
  new ByteArrayInputStream(FileUtils.readFileToByteArray(new File("/some/path/my-filename.ext"))), JaideS3Uploader.CONTENT_TYPE_APPLICATION_OCTETSTREAM);

Uploading a file via Spring

  • Copy and save the "aws-s3.properties.template" as "aws-s3.properties".
  • In that file enter your Amazon S3 access credentials.
  • Place that file somewhere in the classpath or just put it where the .template-file is.

Here's how to upload a file using Spring (if you're making use of the Apache commons-io library):

import de.jaide.s3.JaideS3Uploader;
...
JaideS3SpringService.getJaideS3Uploader().upload("my-file-path", "my-filename.ext",
  new ByteArrayInputStream(FileUtils.readFileToByteArray(new File("/some/path/my-filename.ext"))), JaideS3Uploader.CONTENT_TYPE_APPLICATION_OCTETSTREAM));

Integrating into your code

  • You will need Java 6 and Maven 3 to build the code
  • Choose one of the above two methods to use this library
  • Build your code with Maven
  • You will see that two tests fail - they fail because you didn't provide your S3 access credentials
  • Put them where the two tests, at the top of the files, tell you to put them
  • Build again, this time things should be fine
  • Put the resulting .jar file into your application's library folder

About

A very simple Java wrapper around the Amazon S3 library. One-line-of-code uploading of files to Amazon S3. Use Spring or don't. Zero configuration. Requires Maven for building. Easy to integrate into any Java project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages