I am trying to create am POST method in my MVC ApiController to receive and name file submitted via WebClient.UploadFile. I have searched for a while now and have not found any complete samples of this using ApiController. I have found many that use the same Request object used by the MVC Controller. These all use the Request.Files collection to get the file stream. However, the same property is not found on the Request object exposed by the ApiController.
The following are code snippets from both my client side console application and the server site MVC ApiController.
The client code:
private void executePost(string url, string filename, params KeyValuePair<string, string>[] parms)
{
WebClient client = new WebClient();
parms.ToList().ForEach(k => client.QueryString.Add(k.Key, k.Value));
client.UploadFile(url, "POST", filename);
}
And the pseudo server side ApiController method:
public async Task<HttpResponseMessage> UploadFile(string p1, string p2, string p3)
{
if (Request.Content.IsMimeMultipartContent())
{
var provider = new MultipartFileStreamProvider("/myroot/files");
await Request.Content.ReadAsMultipartAsync(provider)
.ContinueWith(r =>
{
if (r.IsFaulted || r.IsCanceled)
throw new HttpResponseException(HttpStatusCode.InternalServerError);
});
return Request.CreateResponse(HttpStatusCode.OK);
}
}
How do I go about naming the file that is to be written.
Thanks, Jim