I am trying to delete a file from s3 bucket using AWS SDK android. I have followed the tutorial below to set up my bucket. https://grokonez.com/android/uploaddownload-files-images-amazon-s3-android .
The uploading and downloading work fine. But when I try to delete a file, my application crashes.
Here is the code I am using
BasicAWSCredentials credentials = new BasicAWSCredentials(KEY, SECRET);
AmazonS3Client s3Client = new AmazonS3Client(credentials);
s3Client.deleteObject(bucketName, folderPath);
您应该在后台线程中调用删除对象方法。
new Thread(new Runnable() { @Override public void run() { s3client.deleteObject(new DeleteObjectRequest(AWS_BUCKET, "Path")); } }).start();
您的folderPath
变量可能不包含指定存储桶中对象的有效密钥。
You are getting this crash because Android does not let you make a network call from a main thread. You need to wrap this call from a background thread.
new Thread(new Runnable() {
@Override
public void run()
BasicAWSCredentials credentials = new BasicAWSCredentials(KEY, SECRET);
AmazonS3Client s3Client = new AmazonS3Client(credentials);
s3Client.deleteObject(bucketName, folderPath);
}
}).start();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.