tags:

views:

200

answers:

1

Hi, I am helping out a local school out with some projects involving .Net and S3. Of which I am new to both. We want to upload a file via a flash upload form then via .Net to store it on Amazon S3. I have downloaded and gone through the examples but have got myself stuck at this point.

 public string postFile(HttpPostedFile file)
   {
       var recFile = file;
       try
       {
       var client = AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID);
           var request = new PutObjectRequest();
           request.WithMetaData("title", "the title")
                    .WithContentBody(???)
                    .WithBucketName(bucketName)
                    .WithKey(keyName);

           using (S3Response response = client.PutObject(request))
           {
               return keyName;
           }
       }
       ......

I am presuming this is the way to go but have no idea how to actually get it to work. If this is the way, I will persevere, but would appreciate a heads up from anyone who has had experience with this. Thanks.

+1  A: 

Does this work?

public string postFile(HttpPostedFile file)
{
    var recFile = file;
    try
    {
        var client = AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID);
        var request = new PutObjectRequest();

        request.WithMetaData("title", "the title")
        request.WithInputStream(recFile.InputStream); //** Using InputStream
        request.WithBucketName(bucketName);
        request.WithKey(keyName);

        using (S3Response response = client.PutObject(request))
        {
            return keyName;
        }
    ......
Xorcery
That would work, the problem with this approach is that the file would be buffered to disk by ASP.NET, then sent in another request to S3, which would double the effective transfer time. Unfortunately it takes quite a bit of work to write a module to handle the raw stream so bits are transferred on the fly.
Daniel Crenna