title: 'ControllerBase.File(byte[], string)' is a method, which is not valid in the given context (CS0119) - in method
body: <p>I am trying to create an app where user can upload a text file, and gets the altered text back.</p>
  
  <p>I am using React as FE and ASP.NET Core for BE and Azure storage for the database storage.</p>
  
  <p>This is how my HomeController looks like.
  I created a separate "UploadToBlob" method, to post the data</p>
  
  <pre><code>    public class HomeController : Controller
      {
          private readonly IConfiguration _configuration;
  
          public HomeController(IConfiguration Configuration)
          {
              _configuration = Configuration;
          }
  
          public IActionResult Index()
          {
              return View();
          }
  
          [HttpPost("UploadFiles")]
          //OPTION B: Uncomment to set a specified upload file limit
          [RequestSizeLimit(40000000)]
  
          public async Task&lt;IActionResult&gt; Post(List&lt;IFormFile&gt; files)
          {
              var uploadSuccess = false;
              string uploadedUri = null;
  
              foreach (var formFile in files)
              {
                  if (formFile.Length &lt;= 0)
                  {
                      continue;
                  }
  
                  // read directly from stream for blob upload      
                  using (var stream = formFile.OpenReadStream())
                  {
                      // Open the file and upload its data
                      (uploadSuccess, uploadedUri) = await UploadToBlob(formFile.FileName, null, stream);
  
                  }
  
              }
  
              if (uploadSuccess)
              {
                  //return the data to the view, which is react display text component.
                  return View("DisplayText");
              }
              else
              {
                  //create an error component to show there was some error while uploading
                  return View("UploadError");
              }
          }
  
          private async Task&lt;(bool uploadSuccess, string uploadedUri)&gt; UploadToBlob(string fileName, object p, Stream stream)
          {
              if (stream is null)
              {
                  try
                  {
                      string connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");
  
                      // Create a BlobServiceClient object which will be used to create a container client
                      BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
  
                      //Create a unique name for the container
                      string containerName = "textdata" + Guid.NewGuid().ToString();
  
                      // Create the container and return a container client object
                      BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
  
                      string localPath = "./data/";
                      string textFileName = "textdata" + Guid.NewGuid().ToString() + ".txt";
                      string localFilePath = Path.Combine(localPath, textFileName);
  
                      // Get a reference to a blob
                      BlobClient blobClient = containerClient.GetBlobClient(textFileName);
  
                      Console.WriteLine("Uploading to Blob storage as blob:\n\t {0}\n", blobClient.Uri);
  
                      FileStream uploadFileStream = File.OpenRead(localFilePath);
                      await blobClient.UploadAsync(uploadFileStream, true);
                      uploadFileStream.Close();
                  }
                  catch (StorageException)
                  {
                      return (false, null);
                  }
                  finally
                  {
                      // Clean up resources, e.g. blob container
                      //if (blobClient != null)
                      //{
                      //    await blobClient.DeleteIfExistsAsync();
                      //}
                  }
              }
              else
              {
                  return (false, null);
              }
  
          }
  
      }
  </code></pre>
  
  <p>but the console throws errors, saying "'ControllerBase.File(byte[], string)' is a method, which is not valid in the given context (CS0119)"</p>
  
  <p>And because of this error, another error follows "'HomeController.UploadToBlob(string, object, Stream)': not all code paths return a value (CS0161)"</p>
  
  <p>my questions are</p>
  
  <ol>
  <li>Is it a better idea to create a separate method like I did?</li>
  <li>how can I resolve the issue regarding the "File" being valid inside of the UploadToBlob method?</li>
  <li>If I want to add the file type validation, where should it happen? t.ex. only text file is alid</li>
  <li>If I want to read the text string from the uploaded text file, where should I call the </li>
  </ol>
  
  <pre><code>  string contents = blob.DownloadTextAsync().Result;
  
    return contents;
  </code></pre>
  
  <ol start="5">
  <li>How can I pass down the "contents" to my react component? something like this?</li>
  </ol>
  
  <pre><code>    useEffect(() =&gt; {
          fetch('Home')
              .then(response =&gt; response.json())
              .then(data =&gt; {
                  setForcasts(data)
              })
      }, [])
  </code></pre>
  
  <p>Thanks for helping this super newbie with ASP.NET Core!</p>