How to cleanse uploaded files if they are not used? - file

I am allowing users to upload a profile picture of themselves. It involves these steps:
User chooses an image file to upload
Server receives the file through AJAX and stores with a name of temp_userid.jpg
Server returns the image location to the page so the user can see it and make adjustments
The user clicks Save Changes which posts back to the server as final confirmation of the image update
Server loads the temp_userid.jpg, makes the adjustments e.g scale and crop, overwrites any existing profile image, and then finally deletes the temp_userid.jpg image
This works fine as long as the user saves his changes. If the user decides to leave the page, then the temp_userid.jpg file is still on the server and is never deleted. Some of the images can be over 5MB in size which I don't want on the server.
How could I go about cleansing the folders of temp files in a safe manner? I was thinking I could:
Attempt to delete the temp image file whenever the user logs in to his account. The only slight issue here is that the user may never log-in again. But that could be dealt with using some kind of account expiration check.
Attempt to delete all images with a prefix of 'temp_' from the server periodically. The risk here is that it deletes it while a user is still making adjustments to his image which would be terrible!
Are there any better ways of doing this? I'm tagging this as ColdFusion because thats the application server I'm using.

Related

Web3JS - Front or backend

I have a question about web3js.
If my site will load data directly from blockchain (MetaMask) without loading them into the database, and immediately through js bring them to the site then:
1. If a large number of events (1-10 kk) then analyze them on the side of the browser is a bad idea? Need to record everything in the database and the user to publish the analyzed information from the database?
2. When a user enters the site, then in fact his browser parses the information out of the blockchain (if using MetaMask)? Not my server. And I do not care how many connections go through web3js at the same time
What the best?
1. Get all data with web3js and show them on site.
2. Or get all data and writing to database, then use ajax for dinamic show data?

Save data from firebase real time database to android local database (SQLite)

I wanted to save all my data from firebase database into a local database in (JSON format only) for my application to access it when not connected to internet. It consists even images in it along with string form of data.
Firebase allots very less space for offline mode saving data into the application hence can't use it.
I want data to be first saved in my local database and then to be retrieved into the recyclerView of my application.
Moreover I want to save login details as well as other user specific details required to keep the application function without internet into particular user's login.
Searched for answers but no reliable or step by step guide I encountered.
Are these things possible? What should I do ? Please guide.

Should I remove StorageFile from CameraCaptureUI

I'm creating a univeral app to capture a photo or video and upload it to SharePoint via its REST API. The flow of the current prototype is simple:
On the main page, the user clicks a button to capture a photo or video
A photo or video can be captured using the CameraCaptureUI API
The user is redirected to a page where he/she can enter some metadata
If the user clicks the upload button, the file is sent to SharePoint and the user is sent back to the main page
If the user clicks the cancel button, he/she is sent back to the main page
All of this is working, but I'm not sure what to do with the StorageFile after it's not needed anymore. On the phone, the file is saved to some default location. I'm not copying it to the picture library or whatever, after the file is uploaded (or the user cancelled out) I no longer need it on the device.
Should I take care of deleting this StorageFile myself or does the OS handle this when the app is suspended or closed? I want to avoid that the app is slowly eating more and more storage space over time, for example because the user is closing it before the file is uploaded.
On a side note: I'm not using a background task to upload the file. The user needs to monitor the upload (progress bar) and retry if it fails. If the file cannot be uploaded because there's no internet connection or because SharePoint is down, I no longer care about it.
Everything depends on a place where you have stored the file. If you have used local folder for this, then deleting the file may be a good choice as it won't take memory no more.
Nevertheless from what I read, your scenario just fits to temporary location. If you use ApplicationData.TemporaryFolder then you don't need to take care of the file as the OS will handle it when needed:
The temporary app data store works like a cache. Its files do not roam and could be removed at any time. The System Maintenance task can automatically delete data stored at this location at any time. The user can also clear files from the temporary data store using Disk Cleanup. Temporary app data can be used for storing temporary information during an app session. There is no guarantee that this data will persist beyond the end of the app session as the system might reclaim the used space if needed.

What is the best approach to work with data while using token based authentication

I am building an sample application that lets user store comments.
I've created the registration and login process. When the user registers, his details are stored in a MySQL database and a token is returned to the browser. Now he can access the Profile page.
When an existing user logs in he is redirected to the profile page. The profile page is accessible only when a user registers or logs in.
After logging in, I want to show all his comments if he has already added them.
My frontend is in Angular and backend use Laravel. For authentication I use Satellizer.
I want to know, what is the best approach while playing with data, considering the fact that the user will add, edit his comments. Should I use localstorage and store data in a key value pair or should I create a json file which gets updated everytime the user adds a comment or makes a change.
I wanted to know what is the most efficient way to deal with data from server so that the application is fast even when it scales to a 10000 users and lot of data for each user.
Thanks
You should be updating it on the server when changes are made rather than only relying on localstorage. You can use localstorage to cache, but it should only be for immutable data, it shouldn't really be used for data that is going to change.
So in this case you'll be adding and updating new comments via your API (ideally a RESTful one!). Once you've made a change, you could store the comments locally and only update them when the user makes a new comment, however you'll quickly run into issues where the data is invalid on different clients. (i.e. if you update the comments on a different computer, the other computer won't be aware).
Alternatively, you could cache the comments and then simply ping the server to find out if new comments have been added. This could be using a HEAD request for example to check the last modified date on your comments resource.
You can store comments data locally on user browser, but you should properly manage it.
I don't how much load your server will have and if the time invested now worths it.
You can fetch comments and store them locally
User adds a comment, then you update locally and send a request to the server
You need to track the request response, if requests fail so notify user and remove comments from local.
if request was successful so you can continue on your way.
** facebook uses this "success first" approach
user does an action, and he see it happens instantly, in the background it could take few seconds, only if it fails they will notify you.
** look at their commenting process, when you comment, it appears instantly, no loading... but in the BG the load happens.

Automatically Creating Pages on the Server When an Entry in a Database is Created

Using PHP, does anyone know how to make it so that when someone registers on a website (and therefore enters data into a database), a folder with a default php file is created on the web root/server???
This is not a good design. Rather, you should have your PHP files look at the session to find the logged in user's id, and query the necessary data about that user id. You don't need a file for each user. You can make your table auto-increment a user id.

Resources