Reputation: 107
I am using Android aws sdk 3.2 for uploading images from Android phone to amazon s3, this is working fine but i want to compress image before uploading to amazon s3.
I have explored a lot and found few solutions.
Compress image on client side and make copy of that file and upload to S3 after uploading delete that file.
Compress image on client side and upload that image to EC2 server and then upload same image to s3 from EC2.
I am using this code provided by amazon :-
private static AmazonS3Client getS3Client(Context context) {
if (sS3Client == null) {
sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext()));
}
return sS3Client;
}
/**
* Gets an instance of the TransferUtility which is constructed using the
* given Context
*
* @param context
* @return a TransferUtility instance
*/
public static TransferUtility getTransferUtility(Context context) {
if (sTransferUtility == null) {
sTransferUtility = new TransferUtility(getS3Client(context.getApplicationContext()),
context.getApplicationContext());
}
return sTransferUtility;
}
private static CognitoCachingCredentialsProvider getCredProvider(Context context) {
if (sCredProvider == null) {
sCredProvider = new CognitoCachingCredentialsProvider(
context.getApplicationContext(),
Constants.POOL_ID,
Regions.AP_NORTHEAST_1);
}
return sCredProvider;
}
getTransferUtility(context).upload(
"bucket name", uuid,
new File(path));
I want to know does amazon itself provide the facility to compress file then upload or is there a better way of uploading file to s3 after compression?
Upvotes: 1
Views: 3476
Reputation: 1876
You are right about AWS S3. It doesn't support compression. It only accepts file as it is. What you proposed are valid solutions. Unfortunately, the SDK can't help you with compression. Though you can use TransferUtility for upload.
Upvotes: 0