I have a client application that makes a POST
request to asp.net URL
( it is used to uplaod a file to .NET
).
How to make asp.net page receives this request and save it as a file ?
@ Darin Dimitrov
I have tried your code, but I got 500 internal server error
how can I track it ?!
You can send files and binary data directly to Media Server using a POST request. One possible way to send a POST request over a socket to Media Server is using the cURL command-line tool.
The HttpPostedFileBase class is an abstract class that contains the same members as the HttpPostedFile class. The HttpPostedFileBase class lets you create derived classes that are like the HttpPostedFile class, but that you can customize and that work outside the ASP.NET pipeline.
If the client uses multipart/form-data
request encoding (which is the standard for uploading files) you could retrieve the uploaded file from the Request.Files
collection. For example:
protected void Page_Load(object sender, EventArgs e)
{
foreach (HttpPostedFile file in Request.Files)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
}
or if you know the name used by the client you could directly access it:
HttpPostedFile file = Request.Files["file"];
If on the other hand the client doesn't use a standard encoding for the request you might need to read the file from the Request.InputStream
.
You can also save the entire request using
HttpContext.Current.Request.SaveAs(filename,includeHeaders)
Assuming the data is not being uploaded as multipart/form-data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With