Delete asset and temporary link
Hello, I would like to know if there was any possibility to DELETE an asset after a predefined time and if it is possible to change path of an asset (I know it is possible to change its id with rename method but that method does not help me here).
I am coding an app with a form page where users can add medias and text informations.
The idea is to start the upload as soon as the user added any media from the form to divide upload operations and start create a desired data structure for each media, which will be used in the final submit. The goal is to prevent many assets from uploading at the submit time, to provide a better user experience.
The flow would be: user add media in form => in background POST request to a personal API which send media to upload to Cloudinary / at the same time user can go on filling form => when upload complete in background, Cloudinary sends to my API a temporary link to the uploaded asset and my API sends it to the client in an object representing the asset.
The difficulty is if the user never submits form (because he closes the window for example), there will be asset(s) uploaded on Cloudinary which will be never used. I need to find a way to delete the asset and if the user submitted the form, to overwrite the temporary link of each asset.
I have the idea to overwrite the path of each temporary link at the submit, in case of submission, so that the assets remain on Cloudinary and the programed/parametized delete process with temporary link fails (because path would have change) and my API catch and handle error.
I would like to know if you think the flow that I am considering is the good one, and if you have any idea how to do the delete part and temporary link with Cloudinary tools. Thank you for your help!
-
Hi Nicolas,
Thanks for sharing your use case.
I actually think that the `rename` method is the method to use here.
In your use case, there are 2 options, if the user submits the form or not. When the user starts to add media I would upload assets in a directory like `tmp/user_id/`.
When the user submits the form, I would rename all the images from `tmp/user_id/filename` to `user_id/filename`. As mentioned in the documentation here, you can actually use the `overwrite` and `invalidate` parameters and set them to `true` in order to make sure that when renaming, the `tmp` path won't work and all the images will have the last version.
When the user doesn't submit the form, you can actually delete the images in the `tmp/user_id` folder via the destroy method, using the same parameters to remove access to the `tmp` files.
Hope that helps.
Best,
Loic
0
Post is closed for comments.
Comments
1 comment