Having the same problem. If I understand it correctly, only the links of the images are stored in the database. Deleting an image via code from the database, therefore only deletes the link, not the actual image. Is there a way to actually delete the images via code? It would otherwise be quite some work to always delete them manually from the media manger.
You can delete anything you like out of a dataset, whether it be manually by yourself when in the Wix Editor or through code as below.
You can create a password protected admin page and share the password only with the people who should have access to it.
Use dataset actions to control the collection
See more here
Let’s say that you’ve connected a table to your DB collection. Make sure to set the dataset mode as " Read & Write ". Then you should add a table row event and once someone clicks on the table row, it will be deleted from the collection by adding the following code:
import wixData from 'wix-data';
$w.onReady(function () {
export function table1_rowSelect(event, $w) {
//get the index of the row which was clicked by the user
const index = event.rowIndex;
//get the _id attribute of the relevant record
const idToDelete = event.target.rows[index]._id;
//remove the record from the collection
wixData.remove("collectionName", idToDelete)
.then(() => {
//refresh the table with the updated info
$w('#table1').refresh();
})
.catch((err) => {
let errorMsg = err;
});
}
I recommend, to set a password to the page so that only the relevant people will have permission to delete records from your collection.
As an alternative, you can show a lightbox as a confirmation window (to prevent accidental deletions)
See the thread here to get a basic idea on how to achieve that.
I asked the wix support and they explained me that when you delete a record from your db it will also delete the stored file.
So if you have a code to delete the record from your db then your file also be deleted.
The code suggested above is exactly what you need to delete the record.
You do not need to delete the file itself. It will be deleted automatically when the record is deleted.
Hi Martinshn, I am looking to delete user uploaded images from Wix’s media storage too. I tried connecting a dataset so all uploaded images also create an entry in this dataset. I then tried deleting an entry in the dataset but it doesn’t seem to delete any images from my ‘Visitor Uploads’ section. Did you manage to get this working?
This functionality needs to be supported, It seems to be a very bad practice to support media uploading with code but not delete it. All functionalities should have at least it’s opposite.
actually there is a different problem if a user upload a different file/ img than the db will refresh to the new file but will keep the old file in the media library as well.
I found a work around by using aws instead of wix,
so basically im using ifram for upload that uploads the file to aws, on aws i do file management with owner key code from wix db
in wix db i put a link to the file i receiving from aws
and problem solved
i don’t think its very good solution, but its working.
the problem with wix is that the ease of use is on the expanse of flexibility, but they field to understand that some flexibilities are important,
i hope that one they they will user configuration setting where you can change how deep you can customize the system.
also it doesn’t make sense that editor x is only for new sites, while old sites need to be rebuilt and tested in order to move the the new editor x, they should have built in an upgradable option.
Thanks Adam. It’s interesting an the code could be useful.
Anyway I see the problem that AWS has a cost for each transaction and if you setup a community on wix, it’s impossibile to preventi extra costs.
some ideas
Renaming a file before uploading it?
Would it be possibile?
In this way I could name a file with _owner field and try to overwrite it
move users files to specific folders?
We should be able to dynamically create folders and paths
I’ve opened ticket to support about it since it’s a blocking point from my point of view.