2009-12-10 69 views
0

我正在帮助一个当地学校的一些涉及.Net和S3的项目。 其中我对这两个都是新手。我们希望通过Flash上​​传表单上传文件,然后通过.Net将文件存储在Amazon S3上。我已经下载并通过了这些例子,但是让我自己陷入了这一点。上传一个HttpPostedFile到S3

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

我假设这是要走的路,但不知道如何实际上得到它的工作。 如果是这样的话,我会坚持下去,但是要感谢有这方面经验的人。谢谢。

+0

上传文件有什么好运吗?我没有得到我的文件上传:( – balexandre 2010-12-02 04:09:45

回答

2

这是行不通的?

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

这将工作,这种方法的问题是该文件将由ASP.NET缓存到磁盘,然后发送到S3的另一个请求,这将有效传输加倍不幸的是,编写一个模块来处理原始数据流需要花费相当多的工作量,所以比特可以即时传输。 – 2010-01-15 03:10:17