我对html5 formdata有一个奇怪的问题。我使用html5表单数据通过jquery ajax请求将文件发送到服务器。然后使用asp.net webservice接收发布的文件并将文件保存到目录中。
此过程在本地运行良好。一旦我发布到服务器,我收到内部服务器错误500.
一旦我在服务器内部本地运行网站,它的工作。我认为Web服务器的问题无法访问客户端路径?
var formData = new FormData();
for (var i = 0; i < uploadFileArray.length; i++) {
var f = uploadFileArray[i];
formData.append('file' + i, f.file);
}
formData.append('indexdate', indexDate);
formData.append('status', status);
formData.append('category', category);
formData.append('comments', comments ? comments : '');
$.ajax({
type: "POST",
url: serviceUrl,
data: formData,
cache: false,
contentType: false,
processData: false,
beforeSend: function () { $defer.notify(); },
success: function (response) {
$defer.resolve(response)
},
error: function (jqXHR, textStatus, errorThrown) {
$defer.reject(textStatus);
}
});
网络服务
<WebMethod(EnableSession:=True)> _
Public Function UploadFiles() As String
Try
Dim postedContext As HttpContext = HttpContext.Current
Dim indexDate As String = postedContext.Request.Form("indexdate")
Dim status As Integer = Convert.ToInt32(postedContext.Request.Form("status"))
Dim docCategoryKey As String = postedContext.Request.Form("category")
Dim comments As String = postedContext.Request.Form("comments")
' Get the file collection
Dim request As HttpFileCollection = postedContext.Request.Files
For Each filename As String In request
Dim file As HttpPostedFile = request(filename)
'Validate the data
If file Is Nothing Then
Throw New System.IO.FileNotFoundException("Please upload a valid file")
End If
SaveFiles(file, docCategoryKey, comments, status, indexDate)
Next
Catch ex As Exception
Throw ex
End Try
Return ""
End Function