I'm encountering an issue whenever I try to upload a file that is not in .txt format. Text files work fine, but any other type of file results in an error. It seems like this problem didn't exist a year ago because the code went through extensive testing and it would have been caught early on that only .txt files could be uploaded. The server-side code is written in VB.net:
AJAX:
var uFile = new FormData();
var files = $(careerInformationSession.dg).find("#CareerSessionModel_Document_UploadFile").get(0).files;
if (files.length > 0) {
uFile.append("UploadedImage", files[0]);
var ajaxRequest = $.ajax({
type: "POST",
url: careerInformationSession.api + "UploadFile",
contentType: false,
processData: false,
data: uFile,
success: function (data) {
careerInformationSession.uploadSuccess(data);
},
error: function (ts) {
careerInformationSession.callFailure();
}
});
Server side:
<System.Web.Http.HttpPost>
Public Function UploadFile() As String
Dim returnValue As String = String.Empty
If HttpContext.Current.Request.Files.AllKeys.Any() Then
' Get the uploaded image from the Files collection
Dim httpPostedFile As System.Web.HttpPostedFile = HttpContext.Current.Request.Files("UploadedImage")
If httpPostedFile IsNot Nothing Then
Dim validateFile As New ValidateAjaxPostedFile(5120, "JPG,PNG,PDF,JPEG,GIF", httpPostedFile)
If validateFile.Validate() Then
SessionManager.SetSessionData(CWDS.Framework.Utilities.SessionManager.SubSystem.EM, CAREER_INFO_SESSION_FILE, validateFile.FileData)
SessionManager.SetSessionData(CWDS.Framework.Utilities.SessionManager.SubSystem.EM, CAREER_INFO_SESSION_FILE_NAME, System.IO.Path.GetFileName(httpPostedFile.FileName))
Else
Return returnValue
End If
End If
End If
Return returnValue
End Function