2012-03-05 224 views
1

我在ASP.NET MVC应用程序中使用Uploadify。文件上传后,我们看到: enter image description here删除服务器上传的文件

如果用户点击取消/交叉按钮,是否可以删除上载的文件(从服务器)?任何建议/指针都会非常有帮助。

+0

可以将文件流式传输到一个临时文件夹,并且只要他们不打取消假设他们想上传的文件..并做背后在初始文件流成功后场景异步文件上传.. – MethodMan 2012-03-05 16:01:23

回答

2

一种可能性是有,一旦上传完成,可以让你以后识别服务器上的文件服务器端上传的动作返回一个唯一的ID:

[HttpPost] 
public ActionResult Upload() 
{ 
    var fileId = Guid.NewGuid().ToString(); 

    // TODO: do the uploading ... 

    return Json(new { id = fileId }); 
} 

,并在客户端上保持地图之间服务器返回的唯一文件ID和客户端上的ID。然后,你可以订阅onCompleteonCancel事件:

$(function() { 
    var map = {}; 
    $('#file_upload').uploadify({ 
     'uploader': '@Url.Content("~/scripts/uploadify/uploadify.swf")', 
     'script': '@Url.Action("upload")', 
     'cancelImg': '@Url.Content("~/scripts/uploadify/cancel.png")', 
     'auto': true, 
     'removeCompleted': false, 
     'multi': true, 
     'onComplete': function (event, ID, fileObj, response, data) { 
      // once the upload succeeds we retrieve the id returned 
      // by the server and we put it in the map 
      map[ID] = $.parseJSON(response).id; 
     }, 
     'onCancel': function (event, ID, fileObj, data) { 
      var fileId = map[ID]; 
      if (fileId) { 
       // TODO: here you could send a request to the server to 
       // inform him that the user wants to delete the file with 
       // the given unique id 
      } 
     } 
    }); 
}); 
+0

谢谢。我会试一试。 – GoldenUser 2012-03-05 17:56:41