Pass Variable from App structure back to Server Action?

I have a Gallery List. There I got Imagename, ImageID. Below the Images I got a Button called “DELETE IMAGE”. Now that Delete Image calls a Server Delete Action. That works. But how to pass a variable like the Filename back to the ServerActions? So I can delete the Filename? Now I’m using ImageID to make a proper delete Statement in SQL.

I got no Filename Variable to delete the File on my Upload Folders… :

BTW how to make that process safe as I don’t want people to just manipulate any FileVariable to they can delete anything on server… ?

Hi, first of all you need a server connect form with POST variables instead of how you are doing it currently with GET vars.
Using GET and onclick is not secure as using a form, and anybody can run the action and delete everything (as you said).

Check this video please: Delete Database Records it shows how to properly delete record.

In order to delete the related file - before the record delete step add:

  • database query (files table)

  • repeat (database query as expression)

    • inside repeat add remove file step. You get the path/name from the repeat
  • database delete at the end, after repeat.

Okay changed the system now from _GET to _POST and putted the Delete Submit Button als the Post Delete Database Records

But I don’t get it with the delete file. I need to query my files from the User, then repeat query statement/loop action and then delete? hmm if you got a Screenshot or so, that would help alot…

Yes, exactly you need to query the files table. Just follow the steps i provided in my previous answer …

In Server Connect, whenever you want to access a property from a query in a step after it you need to use the repeat step. It does not matter if your query returns one or many records. And in your case you need the name/path saved in the query … and you filter it by the id passed by the POST var.

okay for now it does nothing…

File Remove takes {{filename}} from repeat step…

Repeat1 Expression is the File Query:

image

Have you checked the output for errors? Maybe also enable output results for the file remove steps to see what it returns.

Let me check it. Do I need to Output Fields? But now I remember, that worked similar to old DW… But forgot it.

Query Fields for working with them. So its like a “Workaround” …

  1. Query
  2. Then Delete or whatever, to get the above Query…

Okay better. get now a " 235,“message”:“File doesn’t exist.” Maybe I need to add “If File exists” for proper handling…

It’s not a workaround :slight_smile:
You need to get your path from somewhere - and your path is in the database. We don’t know which column is it stored in, is it a path or a name? You always need to query the table before any manipulation like this.

I use static Upload Path like “/upload” thats it. I dont get the query before the repeat. Do I need to filter that? I mean I want to get back the filename, as I have already/know the path… But in my Query before the Repeat I’m getting back all images from that user. Is that statement to delete all images from the user… ? Looks like…

Freddy, you need a query which is filtered by the FILEID (or whatever your file identity column is called) so that it returns only the file you want to delete. It is the same FILEID you are using in the delete record step!
Then you repeat your query (which is already filtered) and in the repeat step you add the file remove with the path returned by the query…

Ah okay that sounds logic! But strange for me is that Repeat step… Let me try that now!

But I guess it would be better to use IMAGE ID = IMAGE ROW ID from sql. So if I have 500.jpg it would be 500 entry from DB …

See:

Okay that is important to know! I thought its a repeat/loop and is needed for multiple records/happenings … thanx

I’m passing now that value for the deleteimageid which I got already from my button. I guess you speak about that:

That also looks alot safer to me as a delete NEEDS to have:

logged user, advert id and image id.

Okay Update. I tried it now. Enabled all the Outputs, but not getting any errors. DB Delete statement works greatly, but Fileremoval gives me nothing back / debug infos. I try another way.

There is no other way of doing this. This is how it is supposed to be. Have you enabled the “output results” of file remove step?

Yes sure. I need to check that Video from Ben or Hyperbytes I guess I can get it working… hopefully

Thats why I never used filebased galleries and only BLOB …

Well, if you enabled output for file remove then it should provide info!!! Make sure to enable the output for the repeat as well …

Nothing happens… maybe I have some shitty reload stuff on my DELETE button So I get no debug infos? I mean I could fix that If debug would show me some output…

Please paste a screenshot of your console results when the action runs.

Just empty. Enabled all outputs…

Just that crappy Metamask Message, but I can safely ignore that.

Delete Image by ID gives me:

{"queryImagesFromActualUser":[],"repeat1":[],"deleteImageByID":{"identity":"0","affected":0}}

So looks not so bad. But fileremoval isnt working. I saw smth strange, that after Upload of my files, the file had the same OLD date as the original one. For example 2016 etc …

Not that Freddy …
Debugging Problems look what is described here and check the output from the server action.