I have this ASP.NET Core Web API action method:
[HttpPost("PostDir")]
[DisableRequestSizeLimit]
public async Task<IActionResult> PostDir(string serverPath)
{
// Do stuff with file.
return Ok();
}
I don't know what to do with the file I am trying to upload or what it looks like in the action method because the action is never invoked: the client code below gets a 404 response:
public async Task PostDirAsync(string localDirPath, string serverDir)
{
var sourcePath = Path.Combine("Temp", Guid.NewGuid() + ".zip");
ZipFile.CreateFromDirectory(localDirPath, sourcePath, CompressionLevel.Fastest, true);
var rest = new RestClient("http://localhost:50424/api/File/PostDir");
var req = new RestRequest(Method.POST);
req.AddFile(Path.GetFileName(sourcePath), sourcePath);
req.AddHeader("Content-Type", "multipart/form-data");
req.AddParameter("serverPath", serverDir, ParameterType.QueryString);
var resp = rest.Execute(req);
}
What am I missing or doing wrong?