开发者

Store files temporarily on server until a task is completed

开发者 https://www.devze.com 2023-04-07 13:39 出处:网络
I cant use sessions. So heres the scenario: I want the user to upload an image, but that image needs to be a particular si开发者_开发百科ze. So I allow them to upload any size image, store that tempo

I cant use sessions.

So heres the scenario: I want the user to upload an image, but that image needs to be a particular si开发者_开发百科ze. So I allow them to upload any size image, store that temporarily on the server (resize it so it fits on the webpage), display it back to the user, let the user crop it. I then send the crop details back to the server, crop the image and save it and use it as the users profile picture.

I tried to do all this before uploading, but apparently, its a security risk and not allowed.

So how do I temporarily store this file? What if the user does not come back before cropping, I dont want a large image like that sitting on my server. How would I go about removing the file in a stateless application like this?

Files are stored on a CDN.


There are lots of ways to solve this, but perhaps an easy way is that every time a file is uploaded, call a little routine that checks for, and deletes, any 'large' files that are over xxx minutes old.

Alternatively, schedule a job to do the same every xxx minutes in the task scheduler.


You can use TempData, which is similar to Session, but dies after being read.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号