开发者

Uploading a HttpPostedFile to S3

开发者 https://www.devze.com 2022-12-13 13:04 出处:网络
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 Am

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

精彩评论

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