[英]How to display file upload progress in progressbar - Amazon S3 bucket
[英]How to upload memory file to amazon S3?
我想從memoryStream上傳文件到亞馬遜S3服務器。
這是代碼:
public static bool memUploadFile(AmazonS3 client, MemoryStream memFile, string toPath)
{
try
{
Amazon.S3.Transfer.TransferUtility tranUtility = new Amazon.S3.Transfer.TransferUtility(client);
tranUtility.Upload(filePath, toPath.Replace("\\", "/"));
return true;
}
catch (Exception ex)
{
return false;
}
}
然后錯誤說,
“'Amazon.S3.Transfer.TransferUtility.Uplaod(string,string)'的最佳重載方法匹配'有一些無效的參數”
public static bool memUploadFile(AmazonS3 client, MemoryStream memFile, string toPath)
{
try
{
using(Amazon.S3.Transfer.TransferUtility tranUtility =
new Amazon.S3.Transfer.TransferUtility(client))
{
tranUtility.Upload(memFile, toPath.Replace("\\", "/"), <The key under which the Amazon S3 object is stored.>);
return true;
}
}
catch (Exception ex)
{
return false;
}
}
哈姆雷特是對的。 這是TransferUtilityUploadRequest的示例
[Test]
public void UploadMemoryFile()
{
var config = CloudConfigStorage.GetAdminConfig();
string bucketName = config.BucketName;
string clientAccessKey = config.ClientAccessKey;
string clientSecretKey = config.ClientSecretKey;
string path = Path.GetFullPath(@"dummy.txt");
File.WriteAllText(path, DateTime.Now.ToLongTimeString());
using (var client = AWSClientFactory.CreateAmazonS3Client(clientAccessKey, clientSecretKey))
using (var transferUtility = new TransferUtility(client))
{
var request = new TransferUtilityUploadRequest
{
BucketName = bucketName,
Key = "memory.txt",
InputStream = new MemoryStream(File.ReadAllBytes(path))
};
transferUtility.Upload(request);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.