I’m wondering how to do this. I looked at the sdk documentation and have some examples, but am confused how the syntax generally goes.
If I want to delete a file, I assume I use deleteObject(path, key). However, what is the “key”?
Also how do you delete a directory? I can’t seem to find a method for doing that.
A “key” in S3 is similar to a file path:
… is in a bucket named
bucketand has a key ofsome/path/to/use.It’s not actually a path though, because there are no folders. The S3 key is just the file name for a file in one big directory (the entire bucket). S3 keys can contain
/, but it has no special meaning unless you set thedelimiterargument with listing a bucket.In other words, having an object named
some/objectdoesn’t tell you anything about the objectsome(it might or might not exist — the two objects are not related).However, you can request keys with a specific prefix, so I could say “give me all keys starting with
some/path/to/and it will returnsome/path/to/use. It looks like “listing a directory”, but it’s really just asking for files that start with a specific string of characters.I could just as easily name things like this:
And say “give me everything starting with
somepathtouse” (and it would saysomepathtouseaandsomepathtouseb).Note: S3 URL’s come in several forms:
EDIT:
I looked at the JavaDocs and this is the function signature I see (for
AmazonS3Client):EDIT again:
Folders do kind-of exist now, as zero-length objects with a content-type of
application/x-directoryand a key ending in/:This is still just convention and there’s nothing stopping you from having files ending
/or files inside of “folders” that don’t exist.