List of usage examples for com.amazonaws.services.s3 AmazonS3 generatePresignedUrl
public URL generatePresignedUrl(String bucketName, String key, Date expiration) throws SdkClientException;
Returns a pre-signed URL for accessing an Amazon S3 resource.
From source file:com.epam.catgenome.manager.bam.BamHelper.java
License:Open Source License
private SamInputResource getS3Index(SamInputResource samInputResource, BiologicalDataItem indexFile) { Assert.notNull(indexFile.getBucketId(), getMessage(MessagesConstants.ERROR_S3_BUCKET)); final Bucket bucket = bucketManager.loadBucket(indexFile.getBucketId()); Assert.notNull(bucket, getMessage(MessagesConstants.ERROR_S3_BUCKET)); final AmazonS3 s3Client = new AmazonS3Client( new BasicAWSCredentials(bucket.getAccessKeyId(), bucket.getSecretAccessKey())); return samInputResource.index(s3Client.generatePresignedUrl(bucket.getBucketName(), indexFile.getPath(), Utils.getTimeForS3URL())); }
From source file:com.epam.catgenome.manager.bam.BamHelper.java
License:Open Source License
@NotNull private SamInputResource getS3SamInputResource(BamFile bamFile) { final Bucket bucket = bucketManager.loadBucket(bamFile.getBucketId()); Assert.notNull(bucket, getMessage(MessagesConstants.ERROR_S3_BUCKET)); final AmazonS3 s3Client = new AmazonS3Client( new BasicAWSCredentials(bucket.getAccessKeyId(), bucket.getSecretAccessKey())); return SamInputResource.of( s3Client.generatePresignedUrl(bucket.getBucketName(), bamFile.getPath(), Utils.getTimeForS3URL())); }
From source file:com.kirana.services.ProductServicesImpl.java
@Override public List<Product> getProductListByShopId(Shop shop, boolean isImageRequired) throws Exception { List<Product> products = null; try {//from w w w . j a va 2 s. c o m products = productDao.getProductListByShopId(shop.getId()); if (products != null && isImageRequired) { AmazonS3 s3client = getS3Client(); for (Product product : products) { try { product.setProductCodeImageUrl(s3client .generatePresignedUrl(S3_BUCKET_NAME, shop.getName() + "/" + product.getProductCode(), getExpiration(24)) .toExternalForm()); } catch (AmazonClientException ae) { log.warn("No url for object :" + product.getProductCode()); } } } } catch (NullPointerException ex) { log.warn(ex); products = new ArrayList<>(0); } return products; }
From source file:org.systemsbiology.athero.SimpleStoreActivitiesS3Impl.java
License:Open Source License
/** * //from w ww .j av a2 s . com * @param bucket * Name of S3 bucket * @param localName * Name of the file to upload * @param remoteName * Key for the S3 object * @param fromBox * The value for this parameter is used to control the scheduling of this Activity at runtime. * In this case it is putting requirement to run this activity on the machine name passed in. * We want to run this activity on the same box that ran the download. * @return * A Value object */ private String uploadFileToS3(String bucket, String localName, String remoteName) { System.out.println( "uploadToS3 begin bucket=" + bucket + " remoteName=" + remoteName + ", localName=" + localName); AmazonS3 storage = getS3Client(); File f = new File(localName); try { storage.putObject(bucket, remoteName, f); Date expiration = new Date(new Date().getTime() + 1000 * 60 * 30); storage.generatePresignedUrl(bucket, remoteName, expiration); System.out.println("uploadToS3 done"); return storage.generatePresignedUrl(bucket, remoteName, expiration).toString(); } catch (AmazonServiceException e) { String message = "Failure uploading to S3"; System.out.println(message); throw e; } catch (AmazonClientException e) { String message = "Failure uploading to S3"; System.out.println(message); throw e; } }