List of usage examples for com.amazonaws.services.s3 AmazonS3Client setS3ClientOptions
@Override public synchronized void setS3ClientOptions(S3ClientOptions clientOptions)
Override the default S3 client options for this client.
From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.Storage.java
License:Apache License
/** * @param file Local file to upload//from ww w . j av a2s . co m * @param endpoint S3 endpoint URL * @param accessKey Access key * @param secretKey Secret key * @param bucket Bucket name * @param path Key name (path + file name) * @throws Exception On any error */ public static void upload(File file, String endpoint, String accessKey, String secretKey, String bucket, String path) throws Exception { AmazonS3Client amazonS3Client = null; try { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setMaxConnections(MAX_CONNECTIONS); clientConfiguration.setMaxErrorRetry(PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY); clientConfiguration.setConnectionTimeout(ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT); amazonS3Client = new AmazonS3Client(awsCredentials, clientConfiguration); S3ClientOptions clientOptions = new S3ClientOptions().withPathStyleAccess(true); amazonS3Client.setS3ClientOptions(clientOptions); amazonS3Client.setEndpoint(endpoint); // amazonS3Client.putObject(new PutObjectRequest(bucket, path, file)); // up to 5GB TransferManager tm = new TransferManager(amazonS3Client); // up to 5TB Upload upload = tm.upload(bucket, path, file); // while (!upload.isDone()) { upload.getProgress().getBytesTransferred(); Thread.sleep(1000); } // to get progress upload.waitForCompletion(); tm.shutdownNow(); } catch (AmazonServiceException x) { Shrinker.myLogger.info("upload error: " + x.getMessage()); throw new Exception("upload exception", x); } catch (AmazonClientException x) { Shrinker.myLogger.info("upload error: " + x.getMessage()); throw new Exception("upload exception", x); } finally { if (amazonS3Client != null) { try { amazonS3Client.shutdown(); } catch (Exception e) { } } } }
From source file:org.apache.nifi.processors.aws.s3.AbstractS3Processor.java
License:Apache License
private void initalizeEndpointOverride(final ProcessContext context, final AmazonS3Client s3) { // if ENDPOINT_OVERRIDE is set, use PathStyleAccess if (StringUtils .trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue()) .isEmpty() == false) {/*from ww w . j a v a 2s .com*/ final S3ClientOptions s3Options = new S3ClientOptions(); s3Options.setPathStyleAccess(true); s3.setS3ClientOptions(s3Options); } }
From source file:org.geowebcache.s3.S3BlobStoreInfo.java
License:Open Source License
/** @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreInfo}. */ public AmazonS3Client buildClient() { ClientConfiguration clientConfig = new ClientConfiguration(); if (null != useHTTPS) { clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP); }/*from w ww .jav a2s.co m*/ if (null != maxConnections && maxConnections > 0) { clientConfig.setMaxConnections(maxConnections); } clientConfig.setProxyDomain(proxyDomain); clientConfig.setProxyWorkstation(proxyWorkstation); clientConfig.setProxyHost(proxyHost); if (null != proxyPort) { clientConfig.setProxyPort(proxyPort); } clientConfig.setProxyUsername(proxyUsername); clientConfig.setProxyPassword(proxyPassword); if (null != useGzip) { clientConfig.setUseGzip(useGzip); } log.debug("Initializing AWS S3 connection"); AmazonS3Client client = new AmazonS3Client(getCredentialsProvider(), clientConfig); if (endpoint != null && !"".equals(endpoint)) { S3ClientOptions s3ClientOptions = new S3ClientOptions(); s3ClientOptions.setPathStyleAccess(true); client.setS3ClientOptions(s3ClientOptions); client.setEndpoint(endpoint); } if (!client.doesBucketExist(bucket)) { client.createBucket(bucket); } return client; }
From source file:org.gradle.internal.resource.transport.aws.s3.S3Client.java
License:Apache License
private AmazonS3Client createAmazonS3Client(AWSCredentials credentials) { AmazonS3Client amazonS3Client = new AmazonS3Client(credentials, createConnectionProperties()); S3ClientOptions clientOptions = new S3ClientOptions(); Optional<URI> endpoint = s3ConnectionProperties.getEndpoint(); if (endpoint.isPresent()) { amazonS3Client.setEndpoint(endpoint.get().toString()); clientOptions.withPathStyleAccess(true); }//from ww w.j ava 2 s. c om amazonS3Client.setS3ClientOptions(clientOptions); return amazonS3Client; }