I have a bunch of files in s3 that show in the console as ending in "%0A". I'd like to programmatically delete these files.
When I use this method and set the key with suffix "%0A", I get no error but the file is not deleted.
I don't know how it looked when the file was initially written.
S3 Console should be able to delete it no matter what characters it contains or how broken it is (if we're talking about same thing). Do you have enough permissions?
When doing it other ways, first you need to figure out if "%0A" is actually part of the name or is a url encoded LF character ("\n"). Keep in mind that you might not see other non-printable characters as well. The best way to determine this will be to open it in Amazon Console, choose S3 in Service menu, find your Bucket and click on your file, note the object's Link.
If "%0A" is part of the name, you will see object name as "foo%0A", but in the link it will look like "foo%250A". In this case, s3 rm s3://BUCKET/foo%0A
should do the trick.
If "%0A" denotes a url encoded "\n" character, then you should see object name (just above tabs) as just "foo", but will see "foo%0A" as object name in the url. In ths case you need to embed new line into the key when issuing s3 rm
command. This depends on you operating system. E.g. on linux/unix you will enter it like this:
aws-cli s3 rm 's3://BUCKET/foo
'
Note the quotes and that the closing quote is at the begining of a new line. This will make new line part of the value passed as the command line parameter.
Also note that aws-cli might be called just aws on some system, but given you provided s3 rm command as an example I assume you already know what it is on your system. And if using PowerShell on Windows, use backtick in place of quotes.
Now, check the object's Link and see what other characters are there. Looking at your examples and issues you report, I suspect there is more then one in your file names. Important point here is that your object name might include more non-printable characters and you won't see then in S3 console, but Link will include them all in URL encoded form. So, you can extract actual exact name from the link. Note that both aws-cli and programmatic interface you linked take actual name, not url encoded one. So, if you use aws-cli, you will need to embed all non-printable characters into command line parameter. And if you're using programmatic interface you'll need to embed them in the key string you supply to the call (e.g. putting "\n" instead of new line). Though I consider this part pretty obvious. And believe you'll know what to do once you see your actual file name with all the non-printables in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With