I am trying to upload a file from my desktop application to a remote server. After looking at SO for some time, this approach seems to be the cleanest way around this. The problem is that not a single parameter was received on the server side. What am I missing?
private void AddFile(FileInfo fileInfo, int folderId)
{
using (var handler = new HttpClientHandler() {CookieContainer = _cookies})
{
using (var client = new HttpClient(handler) {BaseAddress = new Uri(_host)})
{
var requestContent = new MultipartFormDataContent();
var fileContent = new StreamContent(fileInfo.Open(FileMode.Open));
var folderContent = new StringContent(folderId.ToString(CultureInfo.InvariantCulture));
requestContent.Add(fileContent, "file", "file");
requestContent.Add(folderContent, "folderId", "folderId");
client.PostAsync("/Company/AddFile", requestContent);
}
}
}
edit: This is the signature that the server side expects:
[HttpPost]
public ActionResult AddFile(HttpPostedFileBase file, int folderId)
source
share