title: C# MVC/API - Return an image from Amazon S3 for my API Call
body: <p>I'm using .net core to upload and retrieve an image from a private Amazon S3 bucket. </p>
  
  <p>I'm able to upload it successfully, and even view it after I download it from S3, however when I'm a bit unsure about how to return the stream/response back to the client for the actual API call (for example right now I'm just trying to use Postman/Fiddler proxy tools to get back the image from my API)</p>
  
  <p>My code for S3 to retrieve the stream:</p>
  
  <pre><code>///Retrieve my image from my bucket
  
  public async Task&lt;string&gt; ReadObjectData(MediaFolder key, String fileName)
      {
          string responseBody = "";
          IAmazonS3 client;
  
          using (client = new AmazonS3Client(accessKey, accessSecret, endpoint))
          {
              Amazon.S3.Model.GetObjectRequest request = new Amazon.S3.Model.GetObjectRequest
              {
                  BucketName = bucket,
                  Key = key + "/" + fileName,
              };
              using (GetObjectResponse response = await client.GetObjectAsync(request))
              using (Stream responseStream = response.ResponseStream)
              using (StreamReader reader = new StreamReader(responseStream))
              {
                  string title = response.Metadata["x-amz-meta-title"];
                  responseBody = reader.ReadToEnd();
              }
          }
           return responseBody;
      }
  </code></pre>
  
  <p>So now in my controller, I have the following action:</p>
  
  <pre><code>   [HttpGet("ProfilePic")]
      public async Task&lt;IActionResult&gt; GetProfilePicture()
      {
          var user = await GetUserFromBearerToken();
  
          //Retrieve
          var utf8ImageResponse = await _fileService.ReadObjectData(MediaFolder.Profiles, user.ProfileImageFileName);
  
          //To return a file as a stream
          var imageBytes = System.Text.Encoding.UTF8.GetBytes(utf8ImageResponse);
  
          //Return the image, which I'll hardcode as jpeg for a test
          return File(imageBytes, "image/jpeg");
      }
  </code></pre>
  
  <p>When I make the call using Postman, it returns a little blank box (the box you'd see if you tried to return an image, but it wasn't a valid image or null in some way).</p>
  
  <p>Right now I'm using Postman but ideally I'd want an app to present this image.</p>
  
  <p>Any ideas what I'm doing wrong? I tried messing around with base64 encoding and other things but nothing seems to work.</p>
  
  <p>Thanks!</p>