How to Delete the Digital Ocean Space Image from Python Django

Viewed 542

Please let me know any reference or sample code to how to delete the Digital Ocean Space Image from Python Django, There is example for list and upload the image in Space Image.

Please help me to find the way for my solution

Getting Error like: 'S3' object has no attribute 'delete_file'

Please refer sample code like this

session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='********',
                        aws_secret_access_key='********')
client.delete_file('inspxotestspace',  # Name of Space
                    imagename1)  # Name for remote file

Thanks in advance,

Regards, Kishore

2 Answers

Change delete_file to delete_object like this

session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='********',
                        aws_secret_access_key='********')
client.delete_object(Bucket='inspxotestspace',  Key='imagename1')

And you must include: Bucket=('your_bucket_name') and Key=('your_file_name')

Related