title: Upload image to WEB API, Xamarin.Forms with Media Plugin
body: <p>I created a simple WEB API project to upload image to Microsoft Azure, everything is working fine when I test it with Postman. What I'm trying to do next is to upload the image in Xamarin.Forms Andorid project. I followed the Documentation abailable here: <a href="https://github.com/jamesmontemagno/MediaPlugin" rel="nofollow noreferrer">https://github.com/jamesmontemagno/MediaPlugin</a> and I already created all the necessary files. I have two buttons with onClick events, those two mian functions are responsible for taking&amp;saving and uploading the image :</p>
  <pre><code>  public partial class AddOgloszeniePage : ContentPage
      {
          public MediaFile file;
          public AddOgloszeniePage()
          {
              InitializeComponent();
          }
  
          private async void TapOpenCamera_OnTapped(object sender, EventArgs e)
          {
              await CrossMedia.Current.Initialize();
  
              if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
              {
                  await DisplayAlert(&quot;No Camera&quot;, &quot;:( No camera available.&quot;, &quot;OK&quot;);
                  return;
              }
  
               file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
              {
                  Directory = &quot;Sample&quot;,
                  Name = &quot;test.jpg&quot;
              });
  
              if (file == null)
                  return;
  
              await DisplayAlert(&quot;File Location&quot;, file.Path, &quot;OK&quot;);
  
              ImgOgloszenie.Source = ImageSource.FromStream(() =&gt;
              {
                  var stream = file.GetStream();
                  return stream;
              });
          }
  
  </code></pre>
  <p>and</p>
  <pre><code>        private async void BntSubmit_OnClicked(object sender, EventArgs e)
          {
              var imageArray =  FilesHelper.ReadFully(file.GetStream());
              file.Dispose();
              var wojewodztwo = PickerWojewodztwo.Items[PickerWojewodztwo.SelectedIndex];
              var kategoria = PickerKategoria.Items[PickerKategoria.SelectedIndex];
  
              
              var ogloszeniaUser = new OgloszeniaUser()
              {
                  UserName = EntName.Text,
                  Phone = EntPhone.Text,
                  Email = EntEmail.Text,
                  Item = EntItem.Text,
                  Wojewodztwo = wojewodztwo,
                  Category = kategoria,
                  ImageArray = imageArray,
              };
              ApiServices apiServices = new ApiServices();
              var response = await apiServices.AddItem(ogloszeniaUser);
              if (!response)
              {
                  await DisplayAlert(&quot;error&quot;, &quot;can not add picture&quot;, &quot;close&quot;);
              }
              else
              {
                  await DisplayAlert(&quot;success&quot;, &quot;picture added&quot;, &quot;close&quot;);
              }
          } 
  </code></pre>
  <p>I'm able to take take the picture but I'm unbale to upload it in Xamarin.Forms project despite the fact that I can POST it in Postman. Im getting error: <strong>System.ObjectDisposedException: 'Cannot access a disposed object.'</strong>. I think there is something wrong with the <strong>stream</strong>, but I dont know what exacly is the issue? <a href="https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception?view=net-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception?view=net-5.0</a></p>