本文整理汇总了C#中IAmazonS3.PutObject方法的典型用法代码示例。如果您正苦于以下问题:C# IAmazonS3.PutObject方法的具体用法?C# IAmazonS3.PutObject怎么用?C# IAmazonS3.PutObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAmazonS3
的用法示例。
在下文中一共展示了IAmazonS3.PutObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload_object
public static void Upload_object(string keyName, string filePath)
{
client = new AmazonS3Client("AKIAJWLLQBVBD4TTERPQ", "JOjpTd1crgwOmL99jlhs7qDYk5gpAlDEm2FxeWa6", Amazon.RegionEndpoint.USEast1);
PutObjectRequest request = new PutObjectRequest()
{
BucketName = bucketName,
Key = keyName,
FilePath = filePath
};
PutObjectResponse response2 = client.PutObject(request);
}
示例2: Upload
public static string Upload(string pathToLocalFile, string awsAccessKey, string awsSecretKey, string bucketName, string s3Subfolder, string publicUriBase)
{
using (_client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.EUWest1))
{
var name = Guid.NewGuid() + Path.GetExtension(pathToLocalFile);
try
{
var request = new PutObjectRequest
{
FilePath = pathToLocalFile,
BucketName = bucketName,
Key = s3Subfolder + "/" + name,
CannedACL = S3CannedACL.PublicRead
};
// TODO Handle response codes
// var response =
_client.PutObject(request);
// Return the Full URL for the uploaded image
return publicUriBase + "/" + name;
}
catch (AmazonS3Exception amazonS3Exception)
{
if (amazonS3Exception.ErrorCode != null &&
(amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
{
Console.WriteLine("Please check the provided AWS Credentials.");
Console.WriteLine(
"If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
}
else
{
Console.WriteLine("An error occurred with the message '{0}' when writing an object",
amazonS3Exception.Message);
}
}
catch (AmazonServiceException ase)
{
Console.WriteLine("An Service exception error occurred with the message '{0}' when writing an object",
ase.Message);
}
return null;
}
}
示例3: PutObjectWithQuestionableKey
static void PutObjectWithQuestionableKey(IAmazonS3 s3Client, string bucketName, string keyName)
{
const string testContent = "Some stuff to write as content";
s3Client.PutObject(new PutObjectRequest
{
BucketName = bucketName,
Key = keyName,
ContentBody = testContent
});
var response = s3Client.GetObject(new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
});
using (var s = new StreamReader(response.ResponseStream))
{
var responseContent = s.ReadToEnd();
Assert.AreEqual(testContent, responseContent);
}
}
示例4: PutObjectWithQuestionableKey
static void PutObjectWithQuestionableKey(IAmazonS3 s3Client, string bucketName, string keyName)
{
const string testContent = "Some stuff to write as content";
s3Client.PutObject(new PutObjectRequest
{
BucketName = bucketName,
Key = keyName,
ContentBody = testContent
});
var response = s3Client.GetObject(new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
});
using (var s = new StreamReader(response.ResponseStream))
{
var responseContent = s.ReadToEnd();
Assert.AreEqual(testContent, responseContent);
}
var presignedUrl = s3Client.GetPreSignedURL(new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = keyName,
Verb = HttpVerb.GET,
Expires = DateTime.Now + TimeSpan.FromDays(5)
});
var httpRequest = HttpWebRequest.Create(presignedUrl);
using(var httpResponse = httpRequest.GetResponse())
using(var reader = new StreamReader(httpResponse.GetResponseStream()))
{
var content = reader.ReadToEnd();
Assert.AreEqual(testContent, content);
}
}
示例5: Upload
public override void Upload(string container, string path, IUploadedFile file)
{
client = AWSClientFactory.CreateAmazonS3Client(ExtendedProperties["accessKey"], ExtendedProperties["secretKey"], RegionEndpoint.USEast1);
String S3_KEY = path;
PutObjectRequest request = new PutObjectRequest();
request.BucketName = container;
request.Key = S3_KEY;
request.InputStream = file.Stream;
client.PutObject(request);
}
示例6: PopulateBucket
private void PopulateBucket(IAmazonS3 client, string bucketName)
{
client.PutObject(new PutObjectRequest()
{
BucketName = bucketName,
Key = "Item",
ContentBody = "Attempt number one"
});
for (int i = 0; i < 20; i++)
{
client.PutObject(new PutObjectRequest()
{
BucketName = bucketName,
Key = "Item",
ContentBody = "Atempt " + i
});
}
}