嗨,我尝试过将虚拟文本文件上传到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" />
最佳答案
我遇到了同样的问题,原因是我将服务标签放到了应用标签之外。当我将service标签放在application标签内时,一切工作正常。