Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store a downloaded file object from S3 to a local directory

I'm trying to download a file from S3 using AWS SDK for Java and store the particular file in a local directory in my PC.

The code I wrote for downloading the object is:

public void download(String key) {
S3Object obj=s3Client.getObject(new GetObjectRequest(bucketname,key));
}

But what I actually want to do is to pass the local path as a parameter instead of key and store the downloaded file obj in that particular directory say /tmp/AWSStorage/ in my linux box.

Can you please suggest a way of doing it?

like image 288
Shyamala Selvaganapathy Avatar asked Sep 15 '25 01:09

Shyamala Selvaganapathy


2 Answers

I used:

s3Client.getObject(new GetObjectRequest(bucket,key),file);

It worked fine.

like image 54
Shyamala Selvaganapathy Avatar answered Sep 17 '25 16:09

Shyamala Selvaganapathy


There is an API to directly download file to local path

ObjectMetadata getObject(GetObjectRequest getObjectRequest,
                     File destinationFile)
like image 23
Shiva Kumar Avatar answered Sep 17 '25 14:09

Shiva Kumar