Amazon.S3.IO S3DirectoryInfo

时间:2012-11-13 08:47:48

标签: c# .net amazon-s3 timeout

  

可能重复:
  How to upload files to Amazon S3 (official SDK) that are larger than 5 MB (approx)?

我尝试使用Amazon.S3.IO API。如果我写10mb没有问题。如果我写21mb我得到一个例外:

  

请求已中止:请求已取消。

     

堆栈跟踪:
  在System.Net.ConnectStream.CloseInternal(Boolean internalCall,Boolean aborting)    在System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)    在System.Net.ConnectStream.Dispose(布尔处理)    在System.IO.Stream.Close()    在System.IO.Stream.Dispose()    在Amazon.S3.AmazonS3Client.getRequestStreamCallback [T](IAsyncResult结果)    在Amazon.S3.AmazonS3Client.endOperation [T](IAsyncResult结果)    在Amazon.S3.AmazonS3Client.EndPutObject(IAsyncResult asyncResult)    在Amazon.S3.AmazonS3Client.PutObject(PutObjectRequest请求)    在Amazon.S3.IO.S3FileStream.Flush(布尔flushToS3)    在Amazon.S3.IO.S3FileStream.Dispose(布尔处理)    在System.IO.Stream.Close()    在System.IO.StreamWriter.Dispose(布尔处理)    在System.IO.TextWriter.Dispose()    位于c:\ Program Files(x86)\ AWS SDK for .NET \ Samples \ S3FileSystem_Sample \ S3FileSystem_Sample \ Program.cs:line 106中的S3FileSystem_Sample.Program.createFile(S3DirectoryInfo rootDirectory,String filename)    at S3FileSystem_Sample.Program.Main(String [] args)在c:\ Program Files(x86)\ AWS SDK for .NET \ Samples \ S3FileSystem_Sample \ S3FileSystem_Sample \ Program.cs:第59行    在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)    在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)    在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)    在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)     在System.Threading.ThreadHelper.ThreadStart()

static void createFile(S3DirectoryInfo rootDirectory, string filename)
{ 

    // Creates a file at the root of the bucket.
    S3FileInfo readme = rootDirectory.GetFile(filename);
    char[] buffer = new char[buffersize];  
    fillBuffer(buffer);

    using (StreamWriter writer = new StreamWriter(readme.OpenWrite()))
    {              

        writer.Write(buffer);

    }
}

我知道我可以设置超时吗?

Click herehere了解更多相关问题。

1 个答案:

答案 0 :(得分:4)

不幸的是,Amazon.S3.IO API不支持设置超时,但作为SDK上的开发人员,我会将该功能请求添加到我们的待办事项中。

请记住,Amazon.S3.IO API是一个非常容易使用S3的界面,但它不适合大文件,因为它会将它们缓存到内存中,直到您将文件的全部内容传递给API然后它将它写入S3。对于大型文件,您应该使用Amazon.S3.Transfer命名空间中的TransferUtility。