0

I have the following action method (as suggested by Vague).

public IActionResult Document(string name)
{
  try
  {
    var filepath = $"wwwroot/{name}";
    byte[] fileBytes = System.IO.File.ReadAllBytes(filepath);
    return File(fileBytes, "application/x-msdownload", name);
  }
  catch (Exception exception) { return Ok(exception.Message) }
}

When I execute in locally, I get the files as expected. However, when I upload to Azure, I get the error that the path is wrong.

Could not find a part of the path 'D:\Windows\system32\wwwroot\doc02.doc'.

Assuming that it's about the path being incorrect, I've tried all combinations of prefixing with "~", ".", "./" etc. that I could think of. After a few hours, I realize that it's an ostrich (you can try and try but it ain't gonna fly).

What can I be missing?

I put files to "always upload", of course. And I verified by entering the URL to said files (they are in the root directory, right next to logo.gif).

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • How about storing whole path in db? or saving them in location like ``D:\AppFiles\`` if that's possible. Btw You're sure you want to store ``docs`` in a static files folder? – Joelty Feb 15 '19 at 07:42
  • @Joelty Nope, I'm sure I don't. But it seems like a lot of work to protect them better. Unless you've got a suggestion on how to... – Konrad Viltersten Feb 15 '19 at 15:43
  • I'm saving file somewhere on disk (outside the app), saving its path in db and identifying it with an Id (Guid) e.g ``localhost:5000/download/{guid}`` which then verifies permissions and all business logic, then reaches file from disk with path from db. – Joelty Feb 18 '19 at 08:04
  • @Joelty Thanks for the hint. I'll do that. :) – Konrad Viltersten Feb 18 '19 at 21:36

0 Answers0