title: How to read a file via ASP.Net Web API to S3 via Memory Stream
body: <p>I want to read file as memory stream and send it to s3 bucket. Below is a working snippet which has two part.</p>
  
  <p>Part 1: Takes a file and upload it to a local directory</p>
  
  <p>Part 2: Takes a text and upload it to s3 bucket.</p>
  
  <p>But <em>I want to upload the file to s3 bucket rather than the text</em>.</p>
  
  <p>Below is the code snippet:</p>
  
  <pre><code>[httppost]    
  public async void Upload()
  {
          // Part 1:
  
          // LOGIC TO UPLOAD FILE TO A LOCAL LOCATION 
          var fileuploadPath = ConfigurationManager.AppSettings["FileUploadLocation"];  // some local path
          var provider = new MultipartFormDataStreamProvider(fileuploadPath);
          var content = new StreamContent(HttpContext.Current.Request.GetBufferlessInputStream(true));
          foreach (var header in Request.Content.Headers)
          {
              content.Headers.TryAddWithoutValidation(header.Key, header.Value);
          }
          await content.ReadAsMultipartAsync(provider);
  
          // Part 2:
  
          // LOGIC TO WRITE DATA TO s3 Bucket via Amazon Kinesis
          byte[] dataAsBytes = Encoding.UTF8.GetBytes("My Test Data for s3 bucket");
          using (MemoryStream memoryStream = new MemoryStream(dataAsBytes))
          {
                  Amazon.KinesisFirehose.Model.PutRecordRequest putRecord = new Amazon.KinesisFirehose.Model.PutRecordRequest();
                  putRecord.DeliveryStreamName = myStreamName;
                  Record record = new Record();
                  record.Data = memoryStream; // I WANT TO PUT FILE CONTENT HERE
                  putRecord.Record = record;
                  await kinesisClient.PutRecordAsync(putRecord);
          }
  }
  </code></pre>
  
  <p>In above code snippet, I want to send the file that is getting uploaded to s3 bucket.</p>
  
  <p><strong>Psuedo Code:</strong></p>
  
  <pre><code>Current Code
  byte[] dataAsBytes = Encoding.UTF8.GetBytes("My Test Data for s3 bucket");
  What I want
  byte[] dataAsByte = Data should be read from the file 
  </code></pre>