Delete a file without Model or record in DB


Is there a method to delete a file that have no DB record.
I used direct upload so there is no record on database and no particular model like Attachment or Media.

is there a way to acheive this ?



Your question is lacking details like which are you referring to cache or store bucket in S3, what point in the lifecycle it is like clearing cache or some thing more user action driven, etc.

If there is no DB record, then there isn’t much Shrine can do. You can delete the file in S3 manually or setup a lifecycle rule to periodically purge the cache storage in a typical Shrine setup (do not use this if you need to keep the file) or do a brute force approach where you get the list of all files in your S3 bucket and compare with what’s in your database, then delete all the ones that are not in your db.

You may want to read the Direct uploads guide on clearing caches.


Thanks for the answer.
I guess it’s related to the bucket then…
The point would be to upload a file directly from the client side via a form. then let’s say that the user change the file before saving the form on the server side, the previously uploaded file would be deleted from the bucket. and the new one uploaded. The way i did this, the new file is uploaded but the previous one is still on the bucket. i have a track of the previous track (i use an UI written with react, with a state for the file to keep track of it) so i was wondering how shrine delete file directly on the bucket. but like a i wrote, i guess it’s a bucket issue. if i understand.

Thanks for the links.