0

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?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • Possible duplicate of [Why do I get a 404 trying to post a file to a Core Web API using this code?](https://stackoverflow.com/questions/50737448/why-do-i-get-a-404-trying-to-post-a-file-to-a-core-web-api-using-this-code) – fuzzybear Jun 10 '18 at 04:03
  • @saj Funny, that's also my question. I asked this one here in case it was RestSharp specific. – ProfK Jun 11 '18 at 08:12

0 Answers0