如何从特定文件夹中的Amazon Web Services S3存储桶下载文件。Android亚马逊s3存储桶
截至目前,我在我的android工作室导入amazon传输实用程序项目示例,它的工作正常没有问题,但每当我从AWS-S3下载文件时,将文件下载到默认外部存储位置。 因此,我希望该文件将被下载到特定的文件夹中,例如storage/folder_name/file_name.txt
如何从特定文件夹中的Amazon Web Services S3存储桶下载文件。Android亚马逊s3存储桶
截至目前,我在我的android工作室导入amazon传输实用程序项目示例,它的工作正常没有问题,但每当我从AWS-S3下载文件时,将文件下载到默认外部存储位置。 因此,我希望该文件将被下载到特定的文件夹中,例如storage/folder_name/file_name.txt
试试这个..我在我的项目能够对图像下载到特定文件夹中使用这个..
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){
}
}
找你的欢迎。请如果这个答案帮助你,请接受它。它可以帮助其他人解决如何寻找相同..享受编码......... –
你好安丹,..我能够做到这一点,你建议我..一个更多的问题...我有这么多的文件在S3桶,但我只下载那些我点击的文件...所以,我想从S3桶中下载所有的文件在我loacal /外部存储.....任何进一步的建议相当多.. –
我的图像保存在存储桶中的文件夹中,所以我必须提及该文件夹作为存储桶名称或在密钥中提及它? –