i need to write a code in python that will delete the required file from the amazon s3 bucket, i am able to make connections to the amazon s3 bucket and also able to save files, i just want to know how to delete a file? please help if anyone knows.
A:
Via which interface? Using the REST interface, you just send a delete:
DELETE /ObjectName HTTP/1.1
Host: BucketName.s3.amazonaws.com
Date: date
Content-Length: length
Authorization: signatureValue
Via the SOAP interface:
<DeleteObject xmlns="http://doc.s3.amazonaws.com/2006-03-01">
<Bucket>quotes</Bucket>
<Key>Nelson</Key>
<AWSAccessKeyId> 1D9FVRAYCP1VJEXAMPLE=</AWSAccessKeyId>
<Timestamp>2006-03-01T12:00:00.183Z</Timestamp>
<Signature>Iuyz3d3P0aTou39dzbqaEXAMPLE=</Signature>
</DeleteObject>
If you're using a Python library like this one, it should expose a "delete" feature (delete_key
, in that particular case, which appears to be under-documented).
T.J. Crowder
2010-06-29 12:58:33
yes, i am using that python library, but will that delete, the file ?should i do it this way:k.key = 'images/anon-images/small/'+filenamek.delete_key()is this correct ? please let me know.
Suhail
2010-06-29 13:23:15
@Suhail: I haven't used that library, but from the source I linked, what it's actually doing is a `DELETE` call via the REST interface. So yes, despite the name "delete_key" (which I agree is unclear), it's really deleting the object *referenced* by the key.
T.J. Crowder
2010-06-29 13:40:41
What about removing lot of files with a common prefix in name? Does S3 allow some bulk delete for such case, or deleting them one by one (which is slow) is the must?
Shaman
2010-07-05 10:11:29
@Shaman: I'm not an S3 expert, but as far as I *know*, you can only delete a specific file. But you probably want to actually ask that as a question so it gets attention from S3 experts.
T.J. Crowder
2010-07-05 12:17:04
@T.J. Crowder: Right after commenting here I've added such a question. It has 2 views yet :)
Shaman
2010-07-06 09:38:21
A:
Hi,
for now i have resolved the issue, by using the linux utility s3cmd, i used it like this in python:
delFile= 's3cmd -c /home/project/.s3cfg del s3://images/anon-images/small/' + filename
os.system(delFile)
Thank you Suhail
Suhail
2010-06-29 16:13:34
A:
found one more way to do it using the boto:
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECERET_KEY)
b = Bucket(conn, S3_BUCKET_NAME)
k = Key(b)
k.key = 'images/my-images/'+filename
b.delete_key(k)
Suhail
2010-07-16 12:49:11