JôhÑsk :
Iam loading images from the digital ocean spaces using aws s3 now its download the image to the local storage and then loading the image in image view but i need to load the image directly without downloading the image in local
My Current Code:
AmazonS3Client s3;
BasicAWSCredentials credentials;
TransferUtility transferUtility;
final TransferObserver observer,observers;
String key = "XXXXXXXX";
String secret = "XXXXXXXXXXXXX";
credentials = new BasicAWSCredentials(key, secret);
s3 = new AmazonS3Client(credentials);
s3.setEndpoint("https://xxx.yyyy.com");
transferUtility = new TransferUtility(s3, getApplicationContext());
CannedAccessControlList filePermission = CannedAccessControlList.PublicRead;
observer = transferUtility.download(
"xxx",
"xxxx/01.jpg",
new File("/storage/emulated/0/camera 1/05.jpg")
);
observer.setTransferListener(new TransferListener() {
@Override
public void onStateChanged(int id, TransferState state) {
if (state.COMPLETED.equals(observer.getState())) {
Toast.makeText(getApplicationContext(), "Space Download completed !!", Toast.LENGTH_LONG).show();
Bitmap bmp = BitmapFactory.decodeFile("/storage/emulated/0/camera 1/05.jpg");
imgview.setImageBitmap(bmp);
}
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
}
@Override
public void onError(int id, Exception ex) {
Toast.makeText(getApplicationContext(), "Space Download error: " + ex.getMessage(), Toast.LENGTH_LONG).show();
}
});
JôhÑsk :
@karthikeyan comment helped me here is the answer:
AmazonS3Client s3;
BasicAWSCredentials credentials;
String key = "xxxxx"; //SpacesKey
String secret = "yyyyyyyyy"; //Spaces Secret key
credentials = new BasicAWSCredentials(key, secret);
s3 = new AmazonS3Client(credentials);
s3.setEndpoint("https://RegionName.digitaloceanspaces.com"); //endpoint
Date expires = new Date (new Date().getTime() + 1000 * 60); // 1 minute to expire
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey); //generating the signatured url
generatePresignedUrlRequest.setExpiration(expires);
URL url = s3.generatePresignedUrl(generatePresignedUrlRequest);
load the image to image view using Picasso or Glide with the url