title: calling Amazon S3 from WCF service
body: <p>I try to upload an image from my WCF service to Amazon S3 web server. I have the Amazon S3 code that is working in a web project and my image upload method that is uploading image in Uploded\test.jpg in WCF service. I am not sure how I can use Amazon S3 code  working with WCF service. 1st I don't know how to put Amazon credential in the web confing when I add these line of code inside the  it is not uploading:</p>
  
  <pre><code>    &lt;appSettings&gt;
      &lt;add key="AWSAccessKey" value="myaccessKey"/&gt;
      &lt;add key="AWSSecretKey" value="MySecretKey"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>and this is my method to upload to the WCF server I guess I have to add AWS code when I said //AWS here:</p>
  
  <pre><code>[WebInvoke(UriTemplate = "UploadImage", Method = "POST")]
      Stream UploadImage(Stream request)
      {
  
          Stream requestTest = request;
  
          StreamWriter sw = null;
  
  
          string logpath = HttpContext.Current.Server.MapPath("Uploded\\logtest.txt");
  
          logpath = logpath.Replace("SSGTrnService\\", "");
  
  
          HttpMultipartParser parser = new HttpMultipartParser(request, "file");
  
          string filePath = "";
  
  
          string passed = parser._content;
  
          string sLogFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " ==&gt; ";
          sw = new StreamWriter(logpath);
  
  
          sw.Flush();
  
  
          if (parser.Success)
          {
  
  
              // Save the file somewhere 
              //File.WriteAllBytes(FILE_PATH + title + FILE_EXT, parser.FileContents);
  
              // Save the file 
              //SaveFile( mtp.Filename, mtp.ContentType, mtp.FileContents);
              FileStream fileStream = null;
              BinaryWriter writer = null;
  
  
              try
              {
  
  
                  filePath = HttpContext.Current.Server.MapPath("Uploded\\test.jpg");  // BuildFilePath(strFileName, true);    
  
  
  
  
  
                  filePath = filePath.Replace("SSGTrnService\\", "");
  
                  fileStream = new FileStream(filePath, FileMode.Create);
  
                  fileStream.Write(parser.FileContents, 0, parser.FileContents.Length);
  
                  // return filePath;
              }
              catch (Exception ex)
              {
  
              return "Error: " + ex.Message;
  
              }
              finally
              {
  
                  if (fileStream != null)
                      fileStream.Close();
                  if (writer != null)
                      writer.Close();
                  //AWS Code
  
  
  
              }
          }
  
          //
          // returning text for html DOM
          //
  
          string text = "Image uploaded: " + parser.Filename + " / " + parser.ContentType + filePath + passed;
          System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
          MemoryStream ms = new MemoryStream(encoding.GetBytes(text));
          WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
          return ms;
      }
  </code></pre>
  
  <p>Any Guide in calling Amazon S3 from WCF service would be great.</p>