[Java] NoSuchKey Error when Listing Image Files on Spaces so I can delete them
I have some 4 test image files on my DO Spaces and I need to delete them programmatically in a Java EE environment. I’m using the AWS (v2) SDK. The Java EE system is running on JBoss EAP 7.2.0.
The 4 test image files are created on the following path on DO Spaces console:
So I start with creating a
ListObjectsRequest as follows:
String prefix = "supplies/test_supply_id/supply_images"; ListObjectsRequest listObjectsRequest = ListObjectsRequest .builder() .bucket(BUCKET_NAME) .prefix(prefix) .build();
Then I capture the result:
ListObjectsResponse listObjectsResponse = s3cDOSpaceClient.listObjects(listObjectsRequest); List<S3Object> lsObjectsInBucket = loresListObjectsResponse.contents();
However, I get a
software.amazon.awssdk.services.s3.model.NoSuchKeyException: null (Service: S3, Status Code: 404, Request ID: txREQUEST_ID) at the following line:
ListObjectsResponse listObjectsResponse = s3cDOSpaceClient.listObjects(listObjectsRequest);
What could I really be doing wrong?
I’ve tried different patterns of the prefix, e.g. having a “/” at the end and/or front, but none has worked.
It’s quite hard to find some good documentation on this online, infact even AWS Docs, as described here aren’t helping.
How can I resolve this?