1

How to download file from Amazon web Services S3 bucket in a specific folder.

As of now, I am import amazon transfer Utility project sample in my android studio and it's working fine no problem but whenever I download a file from AWS-S3 bucket the file downloaded in a default external storage location. So, I want the file will be download in a specific folder like storage/folder_name/file_name.txt

2 Answers 2

2

Try this.. I am using this in my project able to download image to particular folder..

 File imageImage = new File(mContext.getDir(USER_PROFILE_DIRECTORY, Context.MODE_PRIVATE)+ ImageName).getAbsoluteFile(); Download(checkImage,Constants.AMAZON_BUCKET_IMAGE,ImageName); /** * To download the image from the Amazon S3 bucket and store the image locally to the particular directory * @param DownloadingImagePath Source path of the image file to be stored * @param ImageName Image file name / Object key of Amazon S3 * @param ImageBucket Amazon S3 bucket name */ public void Download(File DownloadingImagePath,String ImageBucket,String ImageName){ try{ AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY); AmazonS3 s3 = new AmazonS3Client(credentials); java.security.Security.setProperty("networkaddress.cache.ttl" , "60"); s3.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1)); s3.setEndpoint("https://s3-ap-southeast-1.amazonaws.com/"); TransferUtility transferUtility = new TransferUtility(s3, mContext); TransferObserver observer = transferUtility.download(ImageBucket, ImageName, DownloadingImagePath); observer.setTransferListener(new TransferListener() { @Override public void onStateChanged(int id, TransferState state) { //Log.e("Amazon Stats",state.name()); } @Override public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { } @Override public void onError(int id, Exception ex) { } }); } catch (Exception ignored){ } } 
Sign up to request clarification or add additional context in comments.

3 Comments

You'r welcome . Please if this answer help you please accept it. It may help other to solve how are looking for same..Enjoy coding.........
Hello Andan, ..I'm able to do so which you suggest to me..one more question...i have so many file in S3 bucket but i have download only those file which I clicked...So, i want download all the file from S3 bucket in my loacal/external storage.....Any further suggestion considerable..
My images are saved in a folder inside the bucket, so do I have to mention the folder as the bucket name or mention it in the key?
1

You could use the AWS SDK to download a file to any location you would like. Or use a CLI tool like AWS CLI or s3cmd

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.