-1

我尝试通过文件删除插件上传文件,但无法在 UploadHandler.ashx 中获取文件

我需要做的是上传文件

<fieldset id="zone">
  <legend>Drop a file inside&hellip;</legend>
  <p>Or click here to <em>Browse</em>..</p>
</fieldset>

<script type="text/javascript">
    // Tell FileDrop we can deal with iframe uploads using this URL:
    var options = { iframe: { url: 'UploadHandler.ashx'} };
    // Attach FileDrop to an area:
    var zone = new FileDrop('zone',options);

    // Do something when a user chooses or drops a file:
    zone.on.send.push(function (files) {
        alert(files.count.toString());
        // if browser supports files[] will contain multiple items.
        for (var i = 0; i < files.length; i++) {
            files[i].SendTo('UploadHandler.ashx');
            //var file = files[i];
        }
    });
</script>

和 UploadHandler.ashx

context.Response.ContentType = "text/plain";
        HttpFileCollection httpfiles = context.Request.Files;
        for (int i = 0; i < httpfiles.Count; i++)
        {
            HttpPostedFile file = httpfiles[i];
            file.SaveAs(@"C:\"+ Path.GetFileName(file.FileName.ToString()));
        }
        context.Response.Write(httpfiles.Count.ToString());

如何通过 context.Request.Files 获取文件;

4

3 回答 3

0

尝试这个:

Request.InputStream.CopyTo(new FileStream("c:\\temp\" + Request.Params["HTTP_X_FILE_NAME"], FileMode.CreateNew));
于 2013-05-03T14:31:45.123 回答
0

你应该这样写:

     HttpPostedFile  file;
  for(int i=0;i<context.Request.Files.Count;i++)
 {
  file=context.Reqeust.Filed[i];//this can get your file 
  //do something about the file;
 }

于 2014-11-17T02:30:55.820 回答
0

也许你可以看看这个:http ://html5demos.com/file-api 这里还有一些类似的问题:HTML5 FileReader Alternative

于 2013-05-03T14:39:26.403 回答