so i have images in my S3. In android, i uploaded a new image to the same key in S3. In s3, the image did update correctly. But, when i pull that updated image from android using the Glide library with the image's URL, i get the last image file and not the updated one. I have no idea what setting I'm suppose to change in S3 to fix this! I hope someone can help!
Here is how i get my images from s3:
Glide.with(getBaseContext()).load("https://myBucketURL/" + username + "PROFILE_IMAGE").centerCrop().into(my_imageView);
How i upload images into s3:
private void uploadToS3(String imagePath)
{
try
{
observer = transferUtility.upload(
"myBucket", /* The bucket to upload to*/
username + "PROFILE_IMAGE", /* The key for the uploaded object*/
imageStringToFile(imagePath,profileImageFile) /* The file where the data to upload exists*/
);
observer.setTransferListener(new TransferListener()
{
@Override
public void onStateChanged(int id, TransferState state) {
// do something
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
int percentage = (int) (bytesCurrent / bytesTotal * 100);
//Display percentage transfered to user
}
@Override
public void onError(int id, Exception ex) {
// do something
Log.e(PROFILE_IMAGE,"error");
Log.d(PROFILE_IMAGE, ex.getMessage());
}
});
success = true;
Log.d(PROFILE_IMAGE,"upload success!");
} catch (IOException e)
{
e.printStackTrace();
Log.d(PROFILE_IMAGE,"upload failure");
Log.d(PROFILE_IMAGE,e.getMessage());
success = false;
}
}
private File imageStringToFile(String path, String fileName) throws IOException //returns you an image file FROM the image string
{
Bitmap bitmapImage = BitmapFactory.decodeFile(path);
//create a file to write bitmap data
File f = new File(activity.getBaseContext().getCacheDir(), fileName);
f.createNewFile();
//Convert bitmap to byte array
byte[] bitmapdata = ImageCompression.getInstant().getCompressedBitmap(path).toByteArray();
//write the bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
return f;
}
Cheers!