我将AWS Android SDK添加到了我的应用程序,并且我在AsyncTask中有一些代码应该将我的视频上传到我的存储桶,但它不工作。将视频从Android上传到AWS S3
的Android代码:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_VIDEO) {
try {
Uri selectedImageUri = data.getData();
File file = new File(String.valueOf(selectedImageUri));
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"us-east-1:5bfc6b1a-6193-4fXc-823f-ba21a9fadc1b", // Identity Pool ID
Regions.US_EAST_1 // Region
);
// Create an S3 client
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
// Set the region of your S3 bucket
s3.setRegion(Region.getRegion(Regions.US_EAST_1));
TransferUtility transferUtility = new TransferUtility(s3, SellerHomePage.this);
TransferObserver observer = transferUtility.upload(
"willsapptest",
"plzWork",
file
);
observer.setTransferListener(new TransferListener() {
public void onStateChanged(int id, TransferState state) {
//check the state
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
}
public void onError(int id, Exception ex) {
Log.e("", "Error during upload: " + id, ex);
}
});
);
}catch (Exception e){
SevenSecVideoName = (TextView) findViewById(R.id.SevenSecFileNameTxt);
SevenSecVideoName.setText("File Name...");
SevenSecVideoName.setTextColor(Color.parseColor("#797979"));
e.printStackTrace();
Toast.makeText(SellerHomePage.this,"Please pick a valid video",Toast.LENGTH_SHORT).show();
}
}
}
}
我有这样未经授权的用户可以上传从Android监视器S3
错误代码:
03-30 19:27:52.469 2255-2255/com.wilsapp.wilsapp D/CognitoCachingCredentialsProvider: Loading credentials from SharedPreferences
03-30 19:27:52.469 2255-2255/com.wilsapp.wilsapp D/CognitoCachingCredentialsProvider: No valid credentials found in SharedPreferences
03-30 19:27:53.141 2255-2255/com.wilsapp.wilsapp I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
对不起,但你能请澄清答案:D –
刚刚编辑我的意见,希望它可以帮助 – Karthik
好了,帮助!但我现在正在运行我的代码,并在Android监视器中出现此错误(检查问题)我还添加了更多我的代码。 –