I have searched the latest AWS docs for the Android SDK, on the official site. Unfortunately I couldn't find anything related to this. How can I delete a particular -- or multiple -- file(s) or object(s) using the Android SDK?
Asked
Active
Viewed 1,239 times
3 Answers
1
As of mid-2020, the preferred approach for this is to use the AWS Amplify library for Android.
See the documentation for remove()
, in the Storage category. It suggests to do (in Java):
Amplify.Storage.remove(
"myUploadedFileName.txt",
result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getKey()),
error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
OR (in Kotlin):
Amplify.Storage.remove(
"myUploadedFileName.txt",
{ result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getKey()) },
{ error -> Log.e("MyAmplifyApp", "Remove failure", error) }
)

Jameson
- 6,400
- 6
- 32
- 53
0
You can find the Amplify.Storage.remove
method in the amplify official doc itself.
Here is the link
private void removeFile() {
Amplify.Storage.remove(
"myUploadedFileName.txt",
new ResultListener<StorageRemoveResult>() {
@Override
public void onResult(StorageRemoveResult storageRemoveResult) {
Log.i("StorageQuickStart", "Successfully removed: " + storageRemoveResult.getKey());
}
@Override
public void onError(Throwable error) {
Log.e("StorageQuickStart", error.getMessage());
}
}
);
}

Jameson
- 6,400
- 6
- 32
- 53

Sudheesh R
- 1,767
- 3
- 23
- 43
-
thank u Sir but actually I was looking for a solution using Android Sdk of Aws not Amplify Framework which is said is in the development phase not for production usage. – abby Jan 27 '20 at 03:25
-
But in your question you were asked about amplify. – Sudheesh R Jan 27 '20 at 03:34
-
FYI: AWS iOS and Android SDK is now part of the Amplify Framework. You can follow the above documentation. – Sudheesh R Jan 27 '20 at 03:45
-
But Sir at the beginning of Amplify framework page its written its still is in preview stage and not for development purpose now. – abby Jan 27 '20 at 04:24
-
^ Note: As of mid 2020, Amplify is not in preview anymore. – Jameson Jun 08 '20 at 04:11
0
I have found a solution that works, if anyone comes looking it may help, did not find this in the docs of AWS for Android SDk, and the Amplify framework is in preview stage maybe it will come soon after few months. Till then the the solution is:
new Thread(new Runnable() {
@Override
public void run() {
s3Client.deleteObject(bucketName, filePath);
}
}).start();

abby
- 350
- 4
- 21