0
我正在構建一個android應用程序,它拍攝一張照片並將其上傳到Amazon S3。我的代碼似乎運行良好,因爲它實際上正在運行(通過調試斷點確認),但它不是上傳。我沒有收到錯誤消息,並且我放入應用程序的log.d消息沒有出現在logcat中。Android App S3上傳不起作用。沒有錯誤
我第一次跑的代碼,我得到了一個錯誤,抱怨TransferUtility.builder()
沒有必須.s3Client
所以我把在
違規代碼:
private void uploadImage(){
AWSConfiguration awsConfig =
new AWSConfiguration(getActivity().getApplicationContext());
AmazonS3Client s3Client = new AmazonS3Client(IdentityManager.getDefaultIdentityManager()
.getCredentialsProvider().getCredentials());
TransferUtility transferUtility =
TransferUtility.builder()
.context(getActivity().getApplicationContext())
.awsConfiguration(awsConfig)
.s3Client(s3Client)
.build();
TransferObserver uploadObserver =
transferUtility.upload(
"sniffer-gps-app/UserDogPhotos/"+userId+photoFile.getName(),
photoFile);
uploadObserver.setTransferListener(new TransferListener() {
@Override
public void onStateChanged(int id, TransferState state) {
if (TransferState.COMPLETED == state) {
//todo something here
Log.d("S3", "done");
nextFragment();
}
}
@Override
public void onProgressChanged(
int id, long bytesCurrent, long bytesTotal) {
Log.d("S3", "ID: "+id+"\r\nBytesCurrent: "+bytesCurrent+"\r\nBytesTotal: "+bytesTotal);
// TODO Auto-generated method stub
}
@Override
public void onError(int id, Exception ex) {
Log.d("S3", ex.toString());
Integer ID = id;
Log.d("S3", ID.toString());
}
});
}
photoFile
是一個File
對象。
sniffer-gps-app
是鬥名
UserDogPhotos
是在桶
您是否添加了訪問網絡狀態的權限?像這樣: https://github.com/awslabs/aws-sdk-android-samples/blob/master/S3TransferUtilitySample/AndroidManifest.xml#L38 –
我絕對這樣做。打電話給cognito和dynamoDB工作得很好。 – Reid