本文整理汇总了C#中Amazon.S3.Model.PutObjectRequest.WithBucketName方法的典型用法代码示例。如果您正苦于以下问题:C# PutObjectRequest.WithBucketName方法的具体用法?C# PutObjectRequest.WithBucketName怎么用?C# PutObjectRequest.WithBucketName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.Model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.WithBucketName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveObjectInAws
static void SaveObjectInAws(Stream pObject, string keyname)
{
try
{
using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client())
{
// simple object put
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(ConfigurationManager.AppSettings["bucketname"]).WithKey(keyname).WithInputStream(pObject);
using (client.PutObject(request)) { }
}
}
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");
throw;
}
Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
throw;
}
}
示例2: Main
static void Main(string[] args)
{
using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client())
{
try
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
// get file path
string folder = Path.GetFullPath(Environment.CurrentDirectory + "../../../../S3Uploader/");
// write uploader form to s3
const string uploaderTemplate = "uploader.html";
string file = Path.Combine(folder, "Templates/" + uploaderTemplate);
var request = new PutObjectRequest();
request.WithBucketName(appConfig["AWSBucket"])
.WithKey(appConfig["AWSUploaderPath"] + uploaderTemplate)
.WithInputStream(File.OpenRead(file));
request.CannedACL = S3CannedACL.PublicRead;
request.StorageClass = S3StorageClass.ReducedRedundancy;
S3Response response = client.PutObject(request);
response.Dispose();
// write js to s3
var jsFileNames = new[] { "jquery.fileupload.js", "jquery.iframe-transport.js", "s3_uploader.js" };
foreach (var jsFileName in jsFileNames)
{
file = Path.Combine(folder, "Scripts/s3_uploader/" + jsFileName);
request = new PutObjectRequest();
request.WithBucketName(appConfig["AWSBucket"])
.WithKey(appConfig["AWSUploaderPath"] + "js/" + jsFileName)
.WithInputStream(File.OpenRead(file));
request.CannedACL = S3CannedACL.PublicRead;
request.StorageClass = S3StorageClass.ReducedRedundancy;
response = client.PutObject(request);
response.Dispose();
}
}
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);
}
}
}
}
示例3: SaveImage
/// <summary>
/// Saves image to images.climbfind.com
/// </summary>
/// <param name="stream"></param>
/// <param name="filePath"></param>
/// <param name="key"></param>
public override void SaveImage(Stream stream, string filePath, string key)
{
try
{
using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client(Stgs.AWSAccessKey, Stgs.AWSSecretKey, S3Config))
{
// simple object put
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("images.climbfind.com" + filePath);
request.WithInputStream(stream);
request.ContentType = "image/jpeg";
request.Key = key;
request.WithCannedACL(S3CannedACL.PublicRead);
client.PutObject(request);
}
}
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);
}
}
}
示例4: PutImage
public string PutImage(IWebCamImage webCamImage, out string key)
{
if (webCamImage.Data != null) // accept the file
{
// AWS credentials.
const string accessKey = "{sensitive}";
const string secretKey = "{sensitive}";
// Setup the filename.
string fileName = Guid.NewGuid() + ".jpg";
string url = null;
// Drop the image.
AmazonS3 client;
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
{
var request = new PutObjectRequest();
var config = ConfigurationManager.AppSettings;
request.WithBucketName(config["awsBucket"])
.WithCannedACL(S3CannedACL.PublicRead)
.WithKey(fileName).WithInputStream(new MemoryStream(webCamImage.Data));
S3Response response = client.PutObject(request);
url = config["awsRootUrl"] + "/" + config["awsBucket"] + "/" + fileName;
}
// Return our result.
key = fileName;
return url;
}
key = null;
return null;
}
示例5: CreateNewFolder
public static string CreateNewFolder(AmazonS3 client, string foldername)
{
String S3_KEY = foldername;
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(BUCKET_NAME);
request.WithKey(S3_KEY);
request.WithContentBody("");
client.PutObject(request);
return S3_KEY;
}
示例6: PutScreenshot
public void PutScreenshot(Amazon.S3.AmazonS3 amazonS3Client, string bucketName, string path, Stream stream)
{
var putObjectRequest = new PutObjectRequest();
putObjectRequest.WithInputStream(stream);
putObjectRequest.WithBucketName(bucketName);
putObjectRequest.WithKey(path);
amazonS3Client.PutObject(putObjectRequest);
}
示例7: CreateObject
public void CreateObject(string bucketName, Stream fileStream)
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.WithInputStream(fileStream);
request.CannedACL = S3CannedACL.PublicRead;
S3Response response = _client.PutObject(request);
response.Dispose();
}
示例8: CreateNewFileInFolder
public static string CreateNewFileInFolder(AmazonS3 client, string foldername, string filepath)
{
String S3_KEY = foldername + "/" + System.IO.Path.GetFileName(filepath);
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(BUCKET_NAME);
request.WithKey(S3_KEY);
request.WithFilePath(filepath);
//request.WithContentBody("This is body of S3 object.");
client.PutObject(request);
return S3_KEY;
}
示例9: SaveFile
/// <summary>
/// The save file.
/// </summary>
/// <param name="awsAccessKey">
/// The AWS access key.
/// </param>
/// <param name="awsSecretKey">
/// The AWS secret key.
/// </param>
/// <param name="bucket">
/// The bucket.
/// </param>
/// <param name="path">
/// The path.
/// </param>
/// <param name="fileStream">
/// The file stream.
/// </param>
public static void SaveFile(string awsAccessKey, string awsSecretKey, string bucket, string path, Stream fileStream)
{
using (var amazonClient = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey))
{
var createFileRequest = new PutObjectRequest
{
CannedACL = S3CannedACL.PublicRead,
Timeout = int.MaxValue
};
createFileRequest.WithKey(path);
createFileRequest.WithBucketName(bucket);
createFileRequest.WithInputStream(fileStream);
amazonClient.PutObject(createFileRequest);
}
}
示例10: InsertObject
public string InsertObject(Stream stream, string keyName)
{
var putRequest = new PutObjectRequest();
putRequest
.WithBucketName(BucketName)
.WithKey(keyName)
.WithCannedACL(S3CannedACL.PublicRead)
.WithInputStream(stream);
using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
S3Response putResponse = client.PutObject(putRequest);
return string.Format("http://s3.amazonaws.com/{0}/{1}", BucketName, keyName);
}
}
示例11: WriteObjectRequest
public static void WriteObjectRequest(string bucketName, string fileName, Stream fileContent, AmazonS3Client s3Client)
{
if (String.IsNullOrEmpty(fileName))
{
return;
}
PutObjectRequest putObjectRequest = new PutObjectRequest();
putObjectRequest.WithBucketName(bucketName)
.WithKey(fileName)
.WithStorageClass(S3StorageClass.Standard)
.WithCannedACL(S3CannedACL.PublicRead)
.WithInputStream(fileContent);
S3Response response = s3Client.PutObject(putObjectRequest);
response.Dispose();
}
示例12: UploadFileToS3Object
public bool UploadFileToS3Object(string s3ObjectName, string filePath)
{
try
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.WithKey(s3ObjectName);
request.WithFilePath(filePath);//request.WithContentBody
amazonS3Client.PutObject(request);
return true;
}
catch (Exception e)
{
structuredLog("E", "Exception in UploadFileToS3Object: "+e);
return false;
}
}
示例13: AddEntry
public StorageEntry AddEntry(StorageEntry entry)
{
// 本体作成
using (var stream = new MemoryStream(entry.Contents))
{
var request = new PutObjectRequest { InputStream = stream };
request.WithBucketName(BucketName)
.WithKey(entry.Name)
.WithContentType(entry.ContentType);
using (var s3 = GetAmazonS3())
{
var response = s3.PutObject(request);
response.Dispose();
}
}
return entry;
}
示例14: UploadEvents
private void UploadEvents(LoggingEvent[] events, AmazonS3 client)
{
var key = Filename(Guid.NewGuid().ToString());
var content = new StringBuilder(events.Count());
Array.ForEach(events, logEvent =>
{
using (var writer = new StringWriter())
{
Layout.Format(writer, logEvent);
content.AppendLine(writer.ToString());
}
});
var request = new PutObjectRequest();
request.WithBucketName(_bucketName);
request.WithKey(key);
request.WithContentBody(content.ToString());
client.PutObject(request);
}
示例15: ResizeAndUpload
private static void ResizeAndUpload(Stream aStream, AmazonS3 anS3Client, string aBucketName, string aNewImageName, int aSize)
{
Image myOriginal = Image.FromStream(aStream);
Image myActual = ScaleBySize(myOriginal, aSize);
MemoryStream myMemoryStream = imageToMemoryStream(myActual);
PutObjectRequest myRequest = new PutObjectRequest();
myRequest.WithBucketName(aBucketName)
.WithCannedACL(S3CannedACL.PublicRead)
.WithKey(aNewImageName)
.InputStream = myMemoryStream;
S3Response myResponse = anS3Client.PutObject(myRequest);
myActual.Dispose();
myMemoryStream.Dispose();
myOriginal.Dispose();
}