I have a web page
which sends a video file/blob
to another web page in the using FormData
using POST
method and XMLHttpRequest
. I want to return the response as string from the Posted URL
in calling function. i.e after successfull upload file i want to return string to the caller.
index.aspx:
function SendFile(blob)
{
var file = new File([blob], "testfile123.webm");
var oData = new FormData();
oData.append("file", file,"testfile.webm");
var oReq = new XMLHttpRequest();
oReq.open("POST", "upload.aspx", true);
oReq.onload = function (oEvent)
{
if (oReq.status == 200)
{
alert("Uploaded"+oReq.responseText);
}
else {
alert("Error");
}
};
oReq.send(oData);
}
Upload.aspx:
protected void Page_Load(object sender, EventArgs e)
{
string folderPath = GetUploadFolderPath();
string filename = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".webm";
HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++)
{
HttpPostedFile postedFile = fileCollection[i];
var filePath = folderPath + filename; //postedFile.FileName;
postedFile.SaveAs(filePath);
}
}
In above code the file is created at specified location all works fine.I know its not possible in Page_Load
event. please suggest correct method to send responsetext/string after file upload.
Help Appreciated.