title: Upload a long video to web API server from xamarin
body: <p>I'am taking a 5 minute duration video and try to upload it into the API, but the response from the API is false and the video is not present in the Database. I uploaded small sized video to the API.</p>
  
  <p>I found that the size of the video is high it takes more time to upload and the API is time out after some time. How to reduce the size of the video with out reducing it's content or upload a long duration video into the API with in few seconds.</p>
  
  <p>Please help me..</p>
  
  <p>Here is my code </p>
  
  <pre><code>private async void TakeVideo_Clicked(object sender, EventArgs e)
  {
      if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported)
      {
          await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
          return;
      }
  
      var _file = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
      {
          Name = "video.mp4",
          Directory = "Videos",
      });
  
      if (_file == null)
      {
          return;
      }
      else
      {
          _path = _file.Path;
  
          using (var _streamReader = new StreamReader(_file.GetStream()))
          {
              var _array = default(byte[]);                 
  
              using (MemoryStream _memoryStream = new MemoryStream())
              {
                  _streamReader.BaseStream.CopyTo(_memoryStream);
  
                  _array = _memoryStream.ToArray();                        
  
                  if (await DisplayAlert(App._confirmation, "Do you want to save the video?", "Yes", "Cancel"))
                  {
                      FileUploadAsync(_array, false);
                      activity_Indicator.IsVisible = true;
                      activity_Indicator.IsRunning = true;
                  }
                  else
                  {
                      return;
                  }
              }
          }
      }
  }
  
  public async void FileUploadAsync(byte[] fileUpload, bool IsImage)
      {
          APIResponse _response = await App.DataManager.UpdateFilesAsync(ID, fileUpload, IsImage);
  
          if (_response != null)
          {
              activity_Indicator.IsRunning = false;
  
              if (IsImage)
              {
                  DependencyService.Get&lt;IAlertPlayer&gt;().AlertMessege("Image upload successfully");
              }
              else
              {
                  DependencyService.Get&lt;IAlertPlayer&gt;().AlertMessege("Video upload successfully");
              }
          }
          else
          {
              DisplayAlertMessage();
          }
      }      
  
    public async Task&lt;APIResponse&gt;UpdateFilesAsync(int id,byte[] file,bool IsImage)
      {
          Url _url = new Url(BaseURL).AppendPathSegment("sample/UploadFiles");
  
          _url.QueryParams["ID"] = id;
  
          return await Service.POSTFILE&lt;APIResponse&gt;(_url, file,IsImage);
      }
  </code></pre>
  
  <p>Here is my POST method</p>
  
  <pre><code>public async Task&lt;T&gt; POSTFILE&lt;T&gt;(Url url, byte[] uploadFile, bool IsImage)
      {
          try
          {
              using (MultipartFormDataContent content = new MultipartFormDataContent())
              {
                  ByteArrayContent filecontent = new ByteArrayContent(uploadFile);
  
                  if (IsImage)
                  {
                      filecontent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                      {
                          FileName = Guid.NewGuid().ToString() + ".png"
                      };
                  }
                  else
                  {
                      filecontent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                      {
                          FileName = Guid.NewGuid().ToString() + ".mp4"
                      };
                  }
  
                  content.Add(filecontent);
  
                  using (HttpResponseMessage response = await Client.PostAsync(url, content))
                  {
                      string result = await response.Content.ReadAsStringAsync();
                      return JsonConvert.DeserializeObject&lt;T&gt;(result);
                  }
              }
          }
          catch (Exception ex)
          {
  
          }
  
          return default(T);
      }
  }
  </code></pre>