您好,我尝试将一个虚拟文本文件上传到Amazon S3,但是它没有上传成功,但是日志生成了一个ID。当我刷新Amazon S3存储桶仪表板时,文件并未传输。
public class AmazonService extends AsyncTask<String, Boolean, Boolean> {
Context mContext;
public AmazonService(Context context) {
mContext = context;
}
@Override
protected Boolean doInBackground(String... params) {
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
mContext,
"us-east-1:ec361bf5-52b9-477b-9a68-7e2b5f70de07", // Identity Pool ID
Regions.US_EAST_1 // Region
);
AmazonS3Client client =
new AmazonS3Client(credentialsProvider);
TransferUtility transferUtility = new TransferUtility(client, mContext);
TransferObserver observer = transferUtility.upload("elevator-app","Video/",new File("dummy.txt") );
Log.d("Test", observer.getId() + " " + observer.getBytesTransferred());
return true;
}
}
//需要在AndroidManifest.xml中拥有的服务
<service android:name= "com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />