title: Refit upload file from Api to Api
body: <p>I am trying to upload an image from one Asp net core backend to an other via refit.</p>
  
  <pre><code>await _repository.UploadImageAsync(userId,
      new StreamPart(file.OpenReadStream(), file.FileName, file.ContentType), extension);
  </code></pre>
  
  <p>The Api</p>
  
  <pre><code>[Put("/image/{userId}")]
  Task&lt;Guid&gt; UploadImageAsync(Guid userId, StreamPart stream, string extension);
  </code></pre>
  
  <p>The receiving Controller</p>
  
  <pre><code>[HttpPut("image/{userId}")]
  public async Task&lt;IActionResult&gt; UploadImageAsync([FromRoute] Guid userId, StreamPart stream, string extension)
  {
      return await RunAsync(async () =&gt;
      {
          var id = await _userImageManager.UploadImageAsync(userId, stream.Value, extension);
  
          return Ok(id);
      });
  }
  </code></pre>
  
  <p>As soon as I run this i get the following exception:</p>
  
  <pre><code>Newtonsoft.Json.JsonSerializationException: Error getting value from 'ReadTimeout' on 'Microsoft.AspNetCore.Http.ReferenceReadStream'.
   ---&gt; System.InvalidOperationException: Timeouts are not supported on this stream.
     at System.IO.Stream.get_ReadTimeout()
     at lambda_method(Closure , Object )
     at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
     --- End of inner exception stack trace ---
     at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract&amp; memberContract, Object&amp; memberValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
     at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
     at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
     at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
     at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings)
     at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, JsonSerializerSettings settings)
     at Refit.JsonContentSerializer.SerializeAsync[T](T item) in d:\a\1\s\Refit\JsonContentSerializer.cs:line 34
     at Refit.RequestBuilderImplementation.&lt;&gt;c__DisplayClass17_0.&lt;&lt;BuildRequestFactoryForMethod&gt;b__0&gt;d.MoveNext() in d:\a\1\s\Refit\RequestBuilderImplementation.cs:line 546
  --- End of stack trace from previous location where exception was thrown ---
     at Refit.RequestBuilderImplementation.&lt;&gt;c__DisplayClass14_0`2.&lt;&lt;BuildCancellableTaskFuncForMethod&gt;b__0&gt;d.MoveNext() in d:\a\1\s\Refit\RequestBuilderImplementation.cs:line 243
  </code></pre>
  
  <p>I tried going the way described <a href="https://stackoverflow.com/questions/48253505/how-to-upload-files-using-net-core-and-refit">here</a> but had no success. Is there anything I did wrong?</p>
  
  <h1>EDIT</h1>
  
  <p>Based on @TomO answer I edited my code, but I still get null for <code>stream</code>:</p>
  
  <p>Api 1 (the sending part to Api 2):</p>
  
  <pre><code>public async Task&lt;Guid&gt; UploadImageAsync(Guid userId, IFormFile file)
  {
      ...
      var stream = file.OpenReadStream();
  
      var streamPart = new StreamPart(stream, file.FileName, file.ContentType);
      var response = await _repository.UploadImageAsync(userId,
                  streamPart, extension);
      ...
  }
  </code></pre>
  
  <p>Api 2 (The receiver):</p>
  
  <pre><code>[HttpPost("image/{userId}")]
  public async Task&lt;IActionResult&gt; UploadImageAsync([FromRoute] Guid userId, string description, IFormFile stream, string extension)
  {
      ...
  }
  </code></pre>
  
  <p>The Refit Api:</p>
  
  <pre><code>[Multipart]
  [Post("/image/{userId}")]
  Task&lt;Guid&gt; UploadImageAsync(Guid userId, [AliasAs("Description")] string description, [AliasAs("File")] StreamPart stream, string extension);
  </code></pre>