List of usage examples for com.amazonaws.services.s3.model S3Object getObjectContent
public S3ObjectInputStream getObjectContent()
From source file:pl.pawlik.cymes.controllers.FormController.java
@RequestMapping(value = "/plik/{nazwa_pliku}", method = RequestMethod.GET) public void getFile(@PathVariable("nazwa_pliku") String nazwaPliku, HttpServletResponse response) { try {//from www . j a va 2 s. c o m AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJJ4WVVITDZF4SU4A", "oTNfuCbjK/Q/BnBEdQCAs6ogIpoRmbvROAjtdtXV")); S3Object object = s3client.getObject( new GetObjectRequest("pawliktest", "/uploads/upload_2d6303ef-a714-4fa6-9137-fc8b22412730")); InputStream is = object.getObjectContent(); response.setContentType("image/jpeg"); org.apache.commons.io.IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:pl.worker.Main.java
public static BufferedImage getFile(String fileName) throws IOException { AmazonS3 s3Client = new AmazonS3Client(); S3Object s3Object = s3Client.getObject("lab4-weeia", "agnieszka.leszczynska/" + fileName); return ImageIO.read(s3Object.getObjectContent()); }
From source file:prodoc.StoreAmazonS3.java
License:GNU General Public License
/** * * @param Id/*w w w. j ava 2 s . co m*/ * @param Ver * @return * @throws PDException */ protected InputStream Retrieve(String Id, String Ver) throws PDException { try { S3Object object = s3.getObject(new GetObjectRequest(BucketName, GenKey(Id, Ver))); return (object.getObjectContent()); } catch (Exception ex) { PDException.GenPDException("Error_retrieving_content", ex.getLocalizedMessage()); } return (null); }
From source file:prodoc.StoreAmazonS3.java
License:GNU General Public License
/** * * @param Id//from www. ja va2 s . co m * @param Ver * @return * @throws PDException */ protected int Retrieve(String Id, String Ver, OutputStream fo) throws PDException { VerifyId(Id); int Tot = 0; try { S3Object object = s3.getObject(new GetObjectRequest(BucketName, GenKey(Id, Ver))); InputStream in = object.getObjectContent(); int readed = in.read(Buffer); while (readed != -1) { if (isEncript()) DecriptPass(Buffer, readed); fo.write(Buffer, 0, readed); Tot += readed; readed = in.read(Buffer); } in.close(); fo.flush(); fo.close(); } catch (Exception ex) { PDException.GenPDException("Error_retrieving_content", ex.getLocalizedMessage()); } return (Tot); }
From source file:raymond.mockftpserver.S3BucketFileSystem.java
License:Apache License
@Override public FileSystemEntry getEntry(String path) { if (isFile(path)) { S3Object obj = s3.getObject(new GetObjectRequest(bucket, path)); if (obj != null) { FileEntry file = new FileEntry(path); try { try { IOUtils.copy(obj.getObjectContent(), file.createOutputStream(false)); } finally { obj.close();/*from ww w .j a va 2 s. c om*/ } } catch (IOException e) { e.printStackTrace(); } return file; } } return null; }
From source file:s3copy.SimpleCopier.java
License:Apache License
void run(String[] args) throws IOException { SCCmdLine cmdline = new SCCmdLine(); SCCmdLine.Settings settings = cmdline.parse(args); String[] components = settings.input.split("/"); String bucket = components[0]; StringBuilder sb = new StringBuilder(); for (int i = 1; i < components.length; i++) { sb.append(components[i]);/*from w w w .j a v a 2 s .com*/ sb.append("/"); } sb.deleteCharAt(sb.length() - 1); AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials(settings.access_key_id, settings.secret_access_key)); System.out.println("bucket: " + bucket); System.out.println("value: " + sb.toString()); S3Object obj = s3client.getObject(bucket, sb.toString()); InputStream is = obj.getObjectContent(); OutputStream out = null; if (!settings.isURI()) { //local copy out = new FileOutputStream(settings.output); } else { Configuration conf = new Configuration(); if (settings.conf != null) { File _conf = new File(settings.conf); if (_conf.exists()) { if (_conf.isDirectory()) { conf.addResource(new Path(new File(settings.conf, "core-site.xml").getAbsolutePath())); } else { conf.addResource(new Path(settings.conf)); } } } FileSystem fs = FileSystem.get(conf); out = fs.create(new Path(settings.output)); } IOUtils.copyLarge(is, out); out.close(); }
From source file:surrey.repository.impl.S3RepositoryFile.java
License:Open Source License
/** * @see surrey.repository.RepositoryFile#getInputStream() *//*from ww w . j ava 2 s. c o m*/ @Override public InputStream getInputStream() throws IOException { S3Object object = transferManager.getAmazonS3Client().getObject(bucketName, key); long contentLength = object.getObjectMetadata().getContentLength(); S3AbortingInputStream in = new S3AbortingInputStream(object.getObjectContent(), contentLength); return in; }
From source file:surrey.repository.impl.S3RepositoryFile.java
License:Open Source License
/** * @see surrey.repository.RepositoryFile#getInputStream(long, long) *///w ww . j a v a2s .c om @Override public InputStream getInputStream(long start, long length) throws IOException { GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key); getObjectRequest.setRange(start, start + length - 1); S3Object object = transferManager.getAmazonS3Client().getObject(getObjectRequest); return new S3AbortingInputStream(object.getObjectContent(), length); }
From source file:sys2202.aws.s3.Sample.java
License:Open Source License
public static void main(String[] args) throws Exception { // create the client we'll use to connect to S3 AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build(); // list buckets in our S3 account System.out.println("Listing buckets in our S3 account...\n"); for (Bucket bucket : s3.listBuckets()) { System.out.println("\t" + bucket.getName()); }/*from w ww.j a v a2 s. com*/ System.out.println(); // create a new bucket to experiment with String bucketName = "msg8u-sys2202-bucket"; // set the bucket name -- this must be unique, so you'll want to use your ID instead of msg8u System.out.println("Creating bucket " + bucketName + "...\n"); s3.createBucket(bucketName); // list buckets in our S3 account System.out.println("Listing buckets in our S3 account...\n"); for (Bucket bucket : s3.listBuckets()) { System.out.println("\t" + bucket.getName()); } System.out.println(); // create and upload a sample file System.out.println("Uploading a new object to S3 from a local file...\n"); File sampleFile = createSampleFile(); String objectKey = "my-test-file"; PutObjectRequest putRequest = new PutObjectRequest(bucketName, objectKey, sampleFile); s3.putObject(putRequest); // list objects in our new bucket -- notice the new object is now present System.out.println("Listing objects in our new bucket...\n"); ListObjectsRequest listRequest = new ListObjectsRequest().withBucketName(bucketName); ObjectListing objectListing = s3.listObjects(listRequest); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println("\t" + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); // download and display the sample file that we just uploaded System.out.println("Downloading the sample file...\n"); GetObjectRequest getRequest = new GetObjectRequest(bucketName, objectKey); S3Object object = s3.getObject(getRequest); displayTextInputStream(object.getObjectContent()); // delete the sample file from S3 System.out.println("Deleting the sample file...\n"); s3.deleteObject(bucketName, objectKey); // delete the bucket System.out.println("Deleting the bucket...\n"); s3.deleteBucket(bucketName); System.out.println("All done!"); }
From source file:ubicrypt.core.provider.s3.S3Provider.java
License:Open Source License
@Override public Observable<InputStream> get(String pid) { return checker.apply(pid).flatMap(pids -> Observable.<InputStream>create(subscriber -> { if (!initialized.get()) { subscriber.onError(new RuntimeException("s3 not initialized")); return; }/*from ww w . jav a 2 s. co m*/ InputStream is = null; try { S3Object obj = client.getObject(pids.getT1(), pids.getT2()); is = obj.getObjectContent(); subscriber.onNext(is); subscriber.onCompleted(); } catch (AmazonS3Exception e) { Utils.close(is); error(pid, subscriber, e); } catch (Exception e) { subscriber.onError(e); Utils.close(is); } })).subscribeOn(Schedulers.io()); }