In my application I will get the url of s3 file like : https://s3.amazonaws.com/account-update/input.csv I have to download it and then process it. What I already done :
AmazonS3 s3 = new AmazonS3Client(credentials);
S3Object s3object = s3.getObject(new GetObjectRequest(
bucketName, key));
I am able to download the file by providing bucket name and key, but how can I download the file using the url(https://s3.amazonaws.com/account-update/input.csv) only?
When you create a presigned URL, you must provide your security credentials and then specify a bucket name, an object key, an HTTP method (PUT for uploading objects), and an expiration date and time. The presigned URLs are valid only for the specified duration.
Pre-signed URLs are used to provide short-term access to a private object in your S3 bucket. They work by appending an AWS Access Key, expiration time, and Sigv4 signature as query parameters to the S3 object. There are two common use cases when you may want to use them: Simple, occasional sharing of private files.
You could download the file via a standard curl/wget, the same as you would download any other file off the Internet.
The important part, however, is to enable access to the object from Amazon S3. A few options:
You may consider using the AWS SDK class AmazonS3URI as shown below:
URI fileToBeDownloaded = new URI(" https://s3.amazonaws.com/account-update/input.csv");
AmazonS3URI s3URI = new AmazonS3URI(fileToBeDownloaded);
S3Object s3Object = s3Client.getObject(s3URI.getBucket(), s3URI.getKey());
From here on, you should be able to utilise the s3Object obtained in a similar fashion to the s3Object shown in your code.
For more Java related AWS SDK examples on using this class check here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With