开发者

Uploading a HttpPostedFile to S3

I am helping out a local school out with some projects involving .Net and S3. Of which I am new to both.开发者_JAVA百科 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.


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;
        }
    ......
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜