Hello, I, ve created a Timer that deletes objects that lasted more than one month from database table , now my problem is each object has two images stored in the files api, i want to delete those images too, till now i am able to delete objects from database table but i dont know how to delete images related to those objects?
This is the code i am using to delete objects :
execute(req){
let queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setWhereClause( created >= '${Date.now() - 30*24*60*60*1000}'
)
queryBuilder.setSortBy( ‘created desc’ )
queryBuilder.setPageSize(100)
return Backendless.Data.of( ‘PropertyModels’ ).find( queryBuilder )
.then( data => {
if( data.length > 0 ) {
return Backendless.Data.of( ‘PropertyModels’ ).bulkDelete( created >= '${Date.now() - 30*24*60*60*1000}'
)
}
})
.catch( function( error ) {
console.log( "Server reported an error " + error )
})
}
Based on what you described, the algorithm would be:
- Retrieve the objects you want to delete
- Start a loop to iterate over the objects from (1). For each object:
- Get the URL of the first image
- Delete the image at the URL from (3)
- Get the URL of the second image
- Delete the image at the URL from (5)
- Delete the object
Regards,
Mark
Ok, thanks