title: Can't convert a Base64 to MemoryStream
body: <p>I'm having some issues in converting an image from an Base63 string to image memoryStream on a WebApi. The result looks like this:  <a href="https://i.stack.imgur.com/v1oW3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v1oW3.png" alt="enter image description here" /></a></p>
  <p>I have tried several ways ala this:</p>
  <pre><code>            var imageBytes = Convert.FromBase64String(pagedResult.Data);
              var ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
              var image = await Image.LoadAsync(ms, cancellationToken);
              var stream = new MemoryStream();
              await image.SaveAsync(stream, new JpegEncoder(), cancellationToken);
              stream.Position = 0;
              ms.Position = 0;
              
              return (stream, pagedResult.Mimetype);
  </code></pre>
  <p>Or something as simple like this:</p>
  <pre><code>            var sapDoc = Convert.FromBase64String(pagedResult.Data);
          return (new MemoryStream(sapDoc), pagedResult.Mimetype);
  </code></pre>
  <p>The controller looks like this:</p>
  <pre><code>[HttpGet(&quot;document&quot;)]
      public async Task&lt;ActionResult&lt;Stream&gt;&gt; GetImage([FromQuery] long documentNumber, string documentId)
      {
          var query = new GetDocument.Query
          {
              DocumentId = documentId,
              DocumentNumber = documentNumber
          };
  
          var (image, imageFormat) = await _mediator.Send(query);
          return File(image, imageFormat);
  </code></pre>
  <p>Any idea what's going on?
  I have verified the base64 string. If i take the output and use forexample this: <a href="https://codebeautify.org/base64-to-image-converter" rel="nofollow noreferrer">https://codebeautify.org/base64-to-image-converter</a> i can see the image.</p>