0 votes
1 view
in AWS by (18.2k points)

I can't find how to delete multiple objects at once using the ruby aws sdk, in the doc they have a code example on how to delete a folder that contains files :

# batch operations, delete objects in batches of 1k

bucket.objects(prefix: '/tmp-files/').delete

What am looking for is, providing files keys and delete them at once, something like this :

    bucket.objects(keys: [

    'avatars/0b722c42-4003-42cc-887c-b820cad3aed9/avatar1.png',

'avatars/be1275f1-664f-4d47-9890-b5b2a066a18f/avatar2.jpg', 

    'avatars/f5051ed2-b2e7-4844-bdc7-ca19c1900ce8/avatar3.gif'

    ]).delete 

Any idea?

1 Answer

0 votes
by (42.4k points)

You can use delete_objects As the documentation example:

bucket.delete_objects({

  delete: { # required

    objects: [ # required

      {

        key: "ObjectKey", # required

        version_id: "ObjectVersionId",

      },

    ],

    quiet: false,

  },

  mfa: "MFA",

  request_payer: "requester", # accepts requester

})

so in your example:

bucket.delete_objects({

 delete:{

  objects: [

   {key: 'avatars/0b722c42-4003-42cc-887c-b820cad3aed9/avatar1.png'},

   {key:'avatars/be1275f1-664f-4d47-9890-b5b2a066a18f/avatar2.jpg'}, 

   {key:'avatars/f5051ed2-b2e7-4844-bdc7-ca19c1900ce8/avatar3.gif}'

  ]

 }

})

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...