我试图简单地选择一个文件,然后使用asp.net将数据发布到Web服务
这是我的客户端代码:`
<!-- The Modal -->
<div id="uploadModal">
<!-- Modal content -->
<div class="modal-content">
<h3 class="text-center"><i class="fa fa-lock"></i>Upload a video to VideoView</h3>
<!--<form>
<input type="file" id="file" name="file" accept="file_extension|audio/*|video/*|image/*|media_type" />
<br /><br /><button ng-click="getVideo()">Upload</button>
</form>-->
</div>
</div>
<form name="form" method="post" enctype="multipart/form-data">
<--Single Image with validations-->
<div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'" ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100">Select</div>
<button type="submit" ng-click="submit()">submit</button>
</form>
JavaScript Upload.upload({
url: 'Models/Services/videoUpload.asmx',
data: { },
file: file
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
服务器端代码:
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
//var userName = context.Request.Form["name"];
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string fname = context.Server.MapPath("Uploads\\" + "\\" + file.FileName);
file.SaveAs(fname);
}
}
context.Response.ContentType = "text/plain";
context.Response.Write("File/s uploaded successfully!");
}
public bool IsReusable
{
get
{
return false;
}
}
}
我认为客户端似乎运行良好,但是由于任何原因,当我尝试单步执行代码时,它永远不会碰到我的C#端。但是,我尝试使用简单的简单[webmethod],并且不接受能够到达服务器端代码的参数,但是当然不提供任何数据。如果我尝试使用[webmthod]并创建一个称为void videoUpload(byte [])的函数,则永远无法到达服务器端。
我已经断断续续搜索了几个星期,似乎无法弄清楚。我已经做了大量的阅读,只是尝试多次重写服务器端。我想知道这是否与IIS服务器有关?还是我的防火墙不允许我将大量数据上传到服务器?