title: File Upload in Asp.net core 2.0 issue creating 0 byte Image
body: <p>I, am using angular 5, with asp.net core 2.0. I, am trying to upload the file to the server. The code update the file to the server. But with 0 kb of data and sometime it upload the file.</p>
  
  <p>The file size is not large. Its in KB.</p>
  
  <p>Here is the Angular code</p>
  
  <pre><code> public QuestionPostHttpCall(_questionPhotoVM: QuestionPhotoViewModel): Observable&lt;GenericResponseObject&lt;QuestionPhotoViewModel[]&gt;&gt; {
          const formData: FormData = new FormData();
          formData.append('FileUpload', _questionPhotoVM.FileUpload);
          formData.append('QuestionText', _questionPhotoVM.questionText);
          formData.append('QuestionId', _questionPhotoVM.questionId);
          const headers = new HttpHeaders().set('enctype', 'multipart/form-data');
          return this._httpClientModule.post&lt;GenericResponseObject&lt;QuestionPhotoViewModel[]&gt;&gt;(this.questionPhotoUrl, formData);
      }
  </code></pre>
  
  <p>In the controller I, can receive the file.</p>
  
  <p>Here is the controller method</p>
  
  <pre><code>[HttpPost]
  public JsonResult QuestionPhotoPost(IFormFile FileUpload, string QuestionText, Guid? QuestionId)
  {
      string TempFileName = string.Empty;
      var directiveToUpload = Path.Combine(_environment.WebRootPath, "images\\UploadFile");
      var http = HttpRequestExtensions.GetUri(Request);
      QuestionViewModel model = new QuestionViewModel();
      try
      {
  
          if (FileUpload != null)
          {
              TempFileName = FileUpload.FileName;
              CheckFileFromFrontEnd();
          }
  
      }
      catch (Exception exception)
      {
  
      }
  
      void CheckFileFromFrontEnd()
      {
          if (FileUpload != null)
          {
              if (!System.IO.Directory.Exists(directiveToUpload))
              {
                  System.IO.Directory.CreateDirectory(directiveToUpload);
              }
              if (System.IO.File.Exists(string.Format("{0}\\{1}\\{2}", _environment.WebRootPath, "images\\UploadFile", FileUpload.FileName)))
              {
                  TempFileName = Guid.NewGuid().ToString() + FileUpload.FileName;
              }
              model.PictureUrl = string.Format("{0}://{1}/{2}/{3}/{4}", http.Scheme, http.Authority, "images", "UploadFile", TempFileName);
              SaveFileToServer(TempFileName);
          }
  
      }
  
  
      void SaveFileToServer(string FileName)
      {
  
          if (FileUpload.Length &gt; 0)
          {
              using (var stream = new FileStream(Path.Combine(directiveToUpload, FileName), FileMode.Create))
              {
                  FileUpload.CopyToAsync(stream);
              }
          }
  
      }
      return Json(genericResponseObject);
  }
  </code></pre>
  
  <p>The file is uploaded to the server. But some time it upload with 0 byte and sometime it upload correctly.</p>
  
  <p>The resolution of file is 570 X 400 and size of file 197KB</p>
  
  <p>Where I, am doing wrong?? Please anyone let me know. Do, I need to specify max byte in somewhere ??</p>