Hi,
So I’m pretty sure this will work with your version. It’s a couple of previously undocumented methods.
Make sure to always include a filename, or you risk any number of issues. Even if the file does not exist, as long as you have a filename in there, you won’t have any random deletions. And don’t use the * (asterisk) character ever, unless you know what you want from it. Used incorrectly and you could wipe your files clean (probably why this was undocumented).
I’d highly recommend using a separate identifier (like the MySQL ID) as opposed to sending up the filepath directly so that you can check the data for validity.
You will need to make a cloud file, can be called whatever you’d like, I went with remove.lua :
[lua]
–Coronium Cloud / remove.lua
local input = coronium.input()
local fullpath = coronium.io.getPath( input.baseDir, input.filename )
coronium.io.deleteFile( fullpath )
coronium.output( coronium.answer( ‘removed’ … input.filename ) )[/lua]
Usage:
[lua]
–Corona SDK / main.lua
…
coronium:run( ‘remove’, { filename = ‘the-previously-stored-filename.ext’, baseDir = ‘files’ } )
[/lua]
By ID
If you decide to use an ID instead of the path (which you should), it might look like this:
[lua]
coronium:run( ‘remove’, { id = ‘some_id’, baseDir = ‘files’ } )[/lua]
You’d then pull the record, get the path, and remove the file.
If all of your files reside in the same directory, you can hard-code that in the cloud Lua, and leave it out on your call:
[lua]
coronium:run( ‘remove’, { id = ‘some_id’ } )
[/lua]
You’d of course need to make the proper adjustments in your cloud file:
[lua]
local input = coronium.input()
local id = input.id
local baseDir = ‘files’
–look up
local q = “SELECT filename FROM _files
WHERE id=”…input.id
local answer = coronium.mysql.query( { database = ‘_files’ }, q )
local rec = answer.result[1]
local filename = rec.filename
local fullpath = coronium.io.getPath( baseDir, filename )
coronium.io.deleteFile( fullpath )
coronium.output( ‘file deleted - all done’ )
[/lua]
Hope that helps (and more importantly, works).
Cheers.