내 S3에 이미지가 있습니다. 안드로이드에서 S3의 동일한 키에 새 이미지를 업로드했습니다. s3에서 이미지가 올바르게 업데이트되었습니다. 그러나 이미지의 URL이있는 글라이드 라이브러리를 사용하여 업데이트 된 이미지를 안드로이드에서 가져 오면 마지막 이미지 파일이 생성되고 업데이트 된 이미지는 생성되지 않습니다. 이 문제를 해결하기 위해 S3에서 변경해야 할 설정이 무엇인지 잘 모릅니다! 누군가가 도울 수 있기를 바랍니다. 여기s3에서 업데이트 된 개체를 가져올 수 없습니까?
내가 S3에서 내 이미지를 얻을 방법입니다 : 내가 S3에 이미지를 업로드하는 방법
Glide.with(getBaseContext()).load("https://myBucketURL/" + username + "PROFILE_IMAGE").centerCrop().into(my_imageView);
:
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;
}
건배!
이미지를 다시 가져올 때까지 기다리는 중입니까? 이 질문을보십시오 : http://stackoverflow.com/questions/23786609/what-is-maximum-amazon-s3-replication-time-on-file-upload –
앞에 CloudFront와 같은 CDN이 있습니까? S3 버킷? –
흠, 알겠습니다. 사용자가 프로필 사진을 변경하면 사용 사례에 따라 내가하려고하는 것은 현재 사진을 쓰는 것 이상이지만 같은 열쇠를 유지하는 것입니다. 그리고 그들이 프로필 화면으로 돌아올 때마다 나는 그 이미지가 변경되지 않았 음을 알기 때문에 지연이 정말 좋지 않을 것입니다 (심지어 백엔드에도 있음). 지연을 줄이는 방법이 없습니까? 왜냐하면 지금도 앱을 닫고 다시 열거 나 10 분 정도 기다렸다가 이전 프로필 이미지를 계속 유지하기 때문입니다. – TheQ