Delete uploaded image if user goes from the page

时间:2015-05-04 19:54:02

标签: c# jquery html image asp.net-mvc-4

I develop web application functionality sending message with attached image to another user. User can see preview of the image and make some crop before sending. So at first I upload the image to the server and than show this image for user for preview. But what if user just close browser or go to another page, then there will be unused image file on the server. How to handle it? Or maybe there is better approach that don't need to upload image to the server at all?

4 个答案:

答案 0 :(得分:1)

可以使用JavaScript's FileReader完成此操作。您可以在客户端编辑图像,而无需将图像上载到服务器。然后,只有在用户选择发送消息时才能执行上载。本文提供了此类功能的示例:http://www.aspsnippets.com/Articles/Crop-and-Upload-Image-with-Thumbnail-using-jQuery-and-HTML5-in-ASPNet.aspx

答案 1 :(得分:1)

为了提供良好的用户体验,网站应该给予欢迎。因此,在您的情况下,即使浏览器崩溃或标签已关闭,您也可以使用AnonymousIdentification跟踪已归还的用户。

您可以保留与该特定匿名用户相关的信息,并通过其活动(包括图片上传(在您的情况下))跟踪这些信息。然后,如果在特定时间段内没有回来,您可以删除上传的图像。

  

或许有更好的方法,根本不需要将图像上传到服务器?

是的,可以通过HTML5功能实现文件处理和画布功能。

有关详情,请参阅以下链接: Html5_ImageUploader Drag&Drop with Crop via Ajax

答案 2 :(得分:0)

I have built this before with a timestamp, after the crop you remove the timestamp in the table.

Have a service that runs say every 15 minute and looks for unconfirmed images and then delete from the server. This obviously still gives the data transfer but works quite well. I don't know how to handle EACH client close (even browser crashes....)

答案 3 :(得分:0)

此插件http://fengyuanchen.github.io/cropper/
http://deepliquid.com/content/Jcrop.html将裁剪图片而不上传到服务器。