List of usage examples for com.amazonaws.services.s3.model GetObjectRequest GetObjectRequest
public GetObjectRequest(String bucketName, String key)
From source file:com.github.abhinavmishra14.aws.s3.service.impl.AwsS3IamServiceImpl.java
License:Open Source License
@Override public ObjectMetadata downloadObject(final String bucketName, final String key, final String filePath) throws AmazonClientException, AmazonServiceException { LOGGER.info("downloadObject invoked, bucketName: {}, key: {}, filePath: {}", bucketName, key, filePath); final GetObjectRequest getObjRequest = new GetObjectRequest(bucketName, key); return s3client.getObject(getObjRequest, new File(filePath)); }
From source file:com.github.rholder.esthree.command.Get.java
License:Apache License
public MessageDigest retryingGet() throws ExecutionException, RetryException { return (MessageDigest) RetryUtils.AWS_RETRYER.call(new Callable<Object>() { public MessageDigest call() throws Exception { GetObjectRequest req = new GetObjectRequest(bucket, key); S3Object s3Object = amazonS3Client.getObject(req); contentLength = s3Object.getObjectMetadata().getContentLength(); fullETag = s3Object.getObjectMetadata().getETag(); Progress progress = new TransferProgressWrapper(new TransferProgress()); progress.setTotalBytesToTransfer(contentLength); if (progressListener != null) { progressListener.withTransferProgress(progress).withCompleted(0.0).withMultiplier(1.0); }/*from w w w .j av a 2 s. co m*/ InputStream input = null; try { // create the output file, now that we know it actually exists if (output == null) { output = new RandomAccessFile(outputFile, "rw"); } // seek to the start of the chunk in the file, just in case we're retrying output.seek(0); input = s3Object.getObjectContent(); return copyAndHash(input, contentLength, progress); } finally { IOUtils.closeQuietly(input); } } }); }
From source file:com.github.rholder.esthree.command.GetMultipart.java
License:Apache License
public MessageDigest retryingGetWithRange(final long start, final long end) throws ExecutionException, RetryException { return (MessageDigest) RetryUtils.AWS_RETRYER.call(new Callable<Object>() { public MessageDigest call() throws Exception { long totalBytes = end - start + 1; Progress progress = new TransferProgressWrapper(new TransferProgress()); progress.setTotalBytesToTransfer(totalBytes); if (progressListener != null) { progressListener.withTransferProgress(progress).withCompleted((100.0 * start) / contentLength) .withMultiplier( (1.0 * totalBytes / (Math.min(contentLength, chunkSize))) / fileParts.size()); }/*from w w w . java 2 s .c om*/ GetObjectRequest req = new GetObjectRequest(bucket, key).withRange(start, end); S3Object s3Object = amazonS3Client.getObject(req); InputStream input = null; try { // create the output file, now that we know it actually exists if (output == null) { output = new RandomAccessFile(outputFile, "rw"); } // seek to the start of the chunk in the file, just in case we're retrying output.seek(start); input = s3Object.getObjectContent(); return copyAndHash(input, totalBytes, progress); } finally { IOUtils.closeQuietly(input); } } }); }
From source file:com.groupproject.data.FileManager.java
License:Open Source License
public File downloadFile(String key) throws IOException { s3.setRegion(usWest2);/*from ww w.ja va 2 s . c o m*/ File file = File.createTempFile("temp-file", ".txt"); try { s3.getObject(new GetObjectRequest(bucketName, key), file); } 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()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } return file; }
From source file:com.gst.infrastructure.documentmanagement.contentrepository.S3ContentRepository.java
License:Apache License
@Override public FileData fetchFile(final DocumentData documentData) throws DocumentNotFoundException { FileData fileData = null;// ww w .j a va 2 s.c om final String fileName = documentData.fileName(); try { logger.info("Downloading an object"); final S3Object s3object = this.s3Client .getObject(new GetObjectRequest(this.s3BucketName, documentData.fileLocation())); fileData = new FileData(s3object.getObjectContent(), fileName, documentData.contentType()); } catch (final AmazonClientException ace) { logger.error(ace.getMessage()); throw new DocumentNotFoundException(documentData.getParentEntityType(), documentData.getParentEntityId(), documentData.getId()); } return fileData; }
From source file:com.gst.infrastructure.documentmanagement.contentrepository.S3ContentRepository.java
License:Apache License
@Override public ImageData fetchImage(final ImageData imageData) { try {/*w w w . j a v a2s.c o m*/ final S3Object s3object = this.s3Client .getObject(new GetObjectRequest(this.s3BucketName, imageData.location())); imageData.updateContent(s3object.getObjectContent()); } catch (AmazonS3Exception e) { logger.error(e.getMessage()); } return imageData; }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
private BinaryInfo getBinaryInfo(AmazonS3 s3client, String bucketName, String fileName) throws StoreException { logger.info("getBinaryInfo: start."); logger.debug("???={}", bucketName); logger.debug("???={}", fileName); BinaryInfo binary = new BinaryInfo(bucketName); try {/*from w w w .j a v a2s .com*/ S3Object s3binary = s3client.getObject(new GetObjectRequest(bucketName, fileName)); if (null != s3binary) { binary.setFileName(fileName); binary.setContentType(s3binary.getObjectMetadata().getContentType()); binary.setSize(s3binary.getObjectMetadata().getContentLength()); binary.setUrl(s3client.getUrl(binary.getBucketName(), binary.getFileName()).toString()); logger.debug("Generating pre-signed URL."); URL PresignedUrl = getPresignedUrl(s3client, binary.getBucketName(), binary.getFileName()); binary.setPresignedUrl(PresignedUrl.toString()); logger.debug("Pre-Signed URL = " + PresignedUrl.toString()); } } catch (AmazonServiceException ase) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.GET_FAIL, ase, binary.getFileName()); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.GET_FAIL, ace, binary.getFileName()); } logger.info("getBinaryInfo: end."); return binary; }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
@Override public BinaryInfo get(StorageInfo storage, BinaryInfo binary) throws StoreException { logger.debug("={}", storage); logger.debug("?={}", binary); AmazonS3 s3client = getS3Client(binary.getBucketName()); try {/*from w w w. j a va2 s . co m*/ logger.debug("Get an binary"); if (!s3client.doesObjectExist(binary.getBucketName(), binary.getFileName())) { logger.info("The Binary has not exsit.bucket={}, binary={}", binary.getBucketName(), binary.getFileName()); return null; } S3Object s3binary = s3client .getObject(new GetObjectRequest(binary.getBucketName(), binary.getFileName())); binary.setContentType(s3binary.getObjectMetadata().getContentType()); binary.setSize(s3binary.getObjectMetadata().getContentLength()); binary.setUrl(s3client.getUrl(binary.getBucketName(), binary.getFileName()).toString()); logger.debug("Generating pre-signed URL."); URL PresignedUrl = getPresignedUrl(s3client, binary.getBucketName(), binary.getFileName()); binary.setPresignedUrl(PresignedUrl.toString()); logger.debug("Pre-Signed URL = " + PresignedUrl.toString()); } catch (AmazonServiceException ase) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.GET_FAIL, ase, binary.getFileName()); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.GET_FAIL, ace, binary.getFileName()); } return binary; }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
@Override public List<BinaryInfo> list(StorageInfo storage, BinaryInfo binary) throws StoreException { logger.debug("={}", storage); logger.debug("?={}", binary); List<BinaryInfo> objInfoList = new ArrayList<BinaryInfo>(); AmazonS3 s3client = getS3Client(binary.getBucketName()); try {// w ww .ja v a 2 s . c o m logger.debug("Listing binaries"); final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(binary.getBucketName()) .withMaxKeys(2); ListObjectsV2Result result; do { result = s3client.listObjectsV2(req); for (S3ObjectSummary binarySummary : result.getObjectSummaries()) { logger.debug(" - {}(size={})", binarySummary.getKey(), binarySummary.getSize()); if (binarySummary.getSize() != 0) { BinaryInfo objInfo = new BinaryInfo(binary.getBucketName()); objInfo.setFileName(binarySummary.getKey()); objInfo.setSize(binarySummary.getSize()); S3Object s3Object = s3client .getObject(new GetObjectRequest(binary.getBucketName(), binarySummary.getKey())); objInfo.setContentType(s3Object.getObjectMetadata().getContentType()); objInfo.setUrl(s3client.getUrl(binary.getBucketName(), binarySummary.getKey()).toString()); logger.debug("Generating pre-signed URL."); URL PresignedUrl = getPresignedUrl(s3client, binary.getBucketName(), binarySummary.getKey()); objInfo.setPresignedUrl(PresignedUrl.toString()); logger.debug("Pre-Signed URL = " + PresignedUrl.toString()); objInfoList.add(objInfo); } } logger.debug("Next Continuation Token : " + result.getNextContinuationToken()); req.setContinuationToken(result.getNextContinuationToken()); } while (result.isTruncated() == true); } catch (AmazonServiceException ase) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.LIST_FAIL, ase, binary.getFileName()); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.LIST_FAIL, ace, binary.getFileName()); } logger.info(" ={}", objInfoList.size()); return objInfoList; }
From source file:com.haskins.cloudtrailviewer.core.EventLoader.java
License:Open Source License
private InputStream loadEventFromS3(AmazonS3 s3Client, String bucketName, final String key) throws IOException { S3Object s3Object = s3Client.getObject(new GetObjectRequest(bucketName, key)); return s3Object.getObjectContent(); }