I'm having an strange issue with html5 formdata. i'm using the html5 form data to send a file to the server via jquery ajax request. then using asp.net webservice to receive the posted file and saving the file to a directory.
This process worked fine locally. once i published to the server I'm getting an internal server error 500.
once I ran the website locally inside the sever its working. I think the issue with web server cant access the client path?
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);
}
});
Web Service
<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
Aucun commentaire:
Enregistrer un commentaire