早上好,我有一个桌面应用程序将文件上传到 WCF 服务,然后 WCF 服务上传到 Amazon S3。
这是我接收文件并上传到 S3 的 WCF 方法。
public void UploadFile(RemoteFileInfo request)
{
config = new AmazonS3Config();
config.CommunicationProtocol = Protocol.HTTP;
accessKeyID = "XXXXXXX";
secretAccessKeyID = "YYYYYYYY";
client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, config);
int chunkSize = 2048;
byte[] buffer = new byte[chunkSize];
using (System.IO.MemoryStream writeStream = new System.IO.MemoryStream())
{
do
{
// read bytes from input stream
int bytesRead = request.FileByteStream.Read(buffer, 0, chunkSize);
if (bytesRead == 0) break;
// simulates slow connection
System.Threading.Thread.Sleep(3);
// write bytes to output stream
writeStream.Write(buffer, 0, bytesRead);
} while (true);
// report end
Console.WriteLine("Done!");
// start the uploading to S3
PutObjectRequest fileRequest = new PutObjectRequest();
fileRequest.WithInputStream(writeStream);
fileRequest.Key = "testfile.pdf";
fileRequest.WithBucketName("tempbucket");
fileRequest.CannedACL = S3CannedACL.Private;
fileRequest.StorageClass = S3StorageClass.Standard;
client.PutObject(fileRequest);
writeStream.Close();
}
}
在我的客户端上,当我将文件上传到 WCF 服务时,我会实时获得进度,但是当我完成100% 时,这并不意味着文件已经上传到 S3,所以我想知道它是否可以上传在我写入流时将文件写入 S3(在 using 内部
(System.IO.MemoryStream writeStream = new System.IO.MemoryStream())
{
这可能吗?关于如何做的任何指导?
提前欣赏。