本文整理汇总了C#中Amazon.S3.Model.PutObjectRequest.WithKey方法的典型用法代码示例。如果您正苦于以下问题:C# PutObjectRequest.WithKey方法的具体用法?C# PutObjectRequest.WithKey怎么用?C# PutObjectRequest.WithKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.Model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.WithKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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;
}
}
示例6: 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);
}
示例7: UploadFiles
public IList<string> UploadFiles(string path, IList<FileToUpload> files)
{
ValidatePath(path);
var retVal = new List<string>(files.Count);
using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client(new AmazonS3Config().WithServiceURL("s3-us-west-1.amazonaws.com")))
{
string bucketName = ConfigurationManager.AppSettings[Constants.S3_BUCKET];
foreach (FileToUpload file in files)
{
var fileUploadRequest = new PutObjectRequest();
string key = path + Guid.NewGuid() + Path.GetExtension(file.Filename);
fileUploadRequest
.WithKey(key)
.WithCannedACL(S3CannedACL.PublicRead)
.WithBucketName(bucketName)
.WithMetaData("Image-Info",file.MetaInfo)
.WithInputStream(file.Stream);
fileUploadRequest.StorageClass = S3StorageClass.ReducedRedundancy;
//"R" - RFC1123 - http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#RFC1123
fileUploadRequest.AddHeader("Expires", DateTime.UtcNow.AddYears(10).ToString("R"));
fileUploadRequest.AddHeader("Cache-Control", "public, max-age=31536000");
using (client.PutObject(fileUploadRequest))
{
}
retVal.Add(string.Format("http://{0}/{1}", bucketName, key));
}
}
return retVal;
}
示例8: DoUpload
private void DoUpload(string backupPath, PeriodicBackupSetup backupConfigs)
{
var AWSRegion = RegionEndpoint.GetBySystemName(backupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1;
var desc = string.Format("Raven.Database.Backup {0} {1}", Database.Name,
DateTimeOffset.UtcNow.ToString("u"));
if (!string.IsNullOrWhiteSpace(backupConfigs.GlacierVaultName))
{
var manager = new ArchiveTransferManager(awsAccessKey, awsSecretKey, AWSRegion);
var archiveId = manager.Upload(backupConfigs.GlacierVaultName, desc, backupPath).ArchiveId;
logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath),
archiveId));
return;
}
if (!string.IsNullOrWhiteSpace(backupConfigs.S3BucketName))
{
var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, AWSRegion);
using (var fileStream = File.OpenRead(backupPath))
{
var key = Path.GetFileName(backupPath);
var request = new PutObjectRequest();
request.WithMetaData("Description", desc);
request.WithInputStream(fileStream);
request.WithBucketName(backupConfigs.S3BucketName);
request.WithKey(key);
using (S3Response _ = client.PutObject(request))
{
logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}",
Path.GetFileName(backupPath), backupConfigs.S3BucketName, key));
return;
}
}
}
}
示例9: ACLSerial
public static void ACLSerial(String filePath)
{
System.Console.WriteLine("\nhello,ACL!!");
NameValueCollection appConfig = ConfigurationManager.AppSettings;
AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
String bucketName = "chutest";
String objectName = "hello";
//versioning test
String vbucketName = "netversion";
//**********************************************************************************************************************************************************
// Set Version test 環境,目前新增一專用 bucket = netversion,內有兩筆 Object 資訊(Object 已刪除,帶有 delete marker),為了測試方便,此環境不共用也不刪除
// 若於佈板後刪除環境,請預先建立環境,執行132~150行程式
//**********************************************************************************************************************************************************
//PutBucket
/* System.Console.WriteLine("PutBucket-version: {0}\n", vbucketName);
s3Client.PutBucket(new PutBucketRequest().WithBucketName(vbucketName));
//PutBucketVersioning
SetBucketVersioningResponse putVersioningResult = s3Client.SetBucketVersioning(new SetBucketVersioningRequest().WithBucketName(vbucketName).WithVersioningConfig(new S3BucketVersioningConfig().WithStatus("Enabled")));
System.Console.WriteLine("PutBucketVersioning, requestID:{0}\n", putVersioningResult.RequestId);
//PutObject
System.Console.WriteLine("PutObject!");
PutObjectRequest objectVersionRequest = new PutObjectRequest();
objectVersionRequest.WithBucketName(vbucketName);
objectVersionRequest.WithKey(objectName);
objectVersionRequest.WithFilePath(filePath);
PutObjectResponse objectVersionResult = s3Client.PutObject(objectVersionRequest);
System.Console.WriteLine("Uploaded Object Etag: {0}\n", objectVersionResult.ETag);
//DeleteObject
System.Console.WriteLine("Delete Object!");
s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(vbucketName).WithKey(objectName));
*/
//PutBucket
System.Console.WriteLine("PutBucket: {0}\n", bucketName);
s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));
//PutObject
System.Console.WriteLine("PutObject!");
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.WithKey(objectName);
request.WithFilePath(filePath);
PutObjectResponse PutResult = s3Client.PutObject(request);
System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult.ETag);
//PutBucketACL
SetACLRequest aclRequest = new SetACLRequest();
S3AccessControlList aclConfig = new S3AccessControlList();
aclConfig.WithOwner(new Owner().WithDisplayName("hrchu").WithId("canonicalidhrchu"));
aclConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidhrchu","hrchu")).WithPermission(S3Permission.FULL_CONTROL));
aclConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidannyren", "annyren")).WithPermission(S3Permission.READ_ACP));
aclRequest.WithBucketName(bucketName);
aclRequest.WithACL(aclConfig);
SetACLResponse putBucketACLResult = s3Client.SetACL(aclRequest);
System.Console.WriteLine("\nPutBucketACL, requestID:{0}",putBucketACLResult.RequestId);
//GetBucketACL
GetACLResponse getBucketACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName));
System.Console.WriteLine("\nGetBucketACL Result:\n{0}\n",getBucketACLResult.ResponseXml);
//**********************************************************************************************************************************************************
//PutBucketACL (cannedacl)
SetACLRequest cannedaclRequest = new SetACLRequest();
cannedaclRequest.WithBucketName(bucketName);
cannedaclRequest.WithCannedACL(S3CannedACL.PublicRead);
SetACLResponse putBucketCannedACLResult = s3Client.SetACL(cannedaclRequest);
System.Console.WriteLine("\nPutBucketCannedACL, requestID:{0}", putBucketCannedACLResult.RequestId);
//GetBucketACL
GetACLResponse getBucketCannedACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName));
System.Console.WriteLine("\nGetBucketCannedACL Result:\n{0}\n", getBucketCannedACLResult.ResponseXml);
//**********************************************************************************************************************************************************
//PutObjectACL
SetACLRequest objectACLRequest = new SetACLRequest();
S3AccessControlList objectACLConfig = new S3AccessControlList();
objectACLConfig.WithOwner(new Owner().WithDisplayName("hrchu").WithId("canonicalidhrchu"));
objectACLConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidhrchu", "hrchu")).WithPermission(S3Permission.FULL_CONTROL));
objectACLConfig.WithGrants(new S3Grant().WithGrantee(new S3Grantee().WithCanonicalUser("canonicalidannyren", "annyren")).WithPermission(S3Permission.WRITE_ACP));
objectACLRequest.WithBucketName(bucketName);
objectACLRequest.WithKey(objectName);
objectACLRequest.WithACL(objectACLConfig);
SetACLResponse putObjectACLResult = s3Client.SetACL(objectACLRequest);
System.Console.WriteLine("\nPutObjectACL, requestID:{0}", putObjectACLResult.RequestId);
//GetObjectACl
GetACLResponse getObjectACLResult = s3Client.GetACL(new GetACLRequest().WithBucketName(bucketName).WithKey(objectName));
//.........这里部分代码省略.........
示例10: Random
//.........这里部分代码省略.........
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(memoryStream);
}
}
catch (Exception e)
{
}
end = DateTime.UtcNow;//////////////////////////////////////
logger.Log("End Stream Append");
}
if (syncDirection == SynchronizeDirection.Download)
{
logger.Log("Start Stream Get");
logger.Log("Start Stream GetAll");
try
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
byte[] blobContents = blockBlob.DownloadByteArray();
//if (File.Exists(blobName))
// File.Delete(blobName);
begin = DateTime.UtcNow;//////////////////////////////////////
// using (FileStream fs = new FileStream(blobName, FileMode.OpenOrCreate))
// {
byte[] contents = blockBlob.DownloadByteArray();
// fs.Write(contents, 0, contents.Length);
// }
}
catch (Exception e)
{
}
end = DateTime.UtcNow;//////////////////////////////////////
logger.Log("End Stream Get");
logger.Log("End Stream GetAll");
}
#endregion
}
else if (synchronizerType == SynchronizerType.AmazonS3)
{
#region amazon s3 stuff
if (containerName == null)
containerName = "testingraw";
if (blobName == null)
blobName = Guid.NewGuid().ToString();
AmazonS3Client amazonS3Client = new AmazonS3Client(accountName, accountKey);
if (syncDirection == SynchronizeDirection.Upload)
{
ListBucketsResponse response = amazonS3Client.ListBuckets();
foreach (S3Bucket bucket in response.Buckets)
{
if (bucket.BucketName == containerName)
{
break;
}
}
amazonS3Client.PutBucket(new PutBucketRequest().WithBucketName(containerName));
begin = DateTime.UtcNow;//////////////////////////////////////
MemoryStream ms = new MemoryStream();
ms.Write(input, 0, input.Length);
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(containerName);
request.WithKey(blobName);
request.InputStream = ms;
amazonS3Client.PutObject(request);
end = DateTime.UtcNow;//////////////////////////////////////
}
if (syncDirection == SynchronizeDirection.Download)
{
if (File.Exists(blobName))
File.Delete(blobName);
begin = DateTime.UtcNow;//////////////////////////////////////
GetObjectRequest request = new GetObjectRequest();
request.WithBucketName(containerName);
request.WithKey(blobName);
GetObjectResponse response = amazonS3Client.GetObject(request);
var localFileStream = File.Create(blobName);
response.ResponseStream.CopyTo(localFileStream);
localFileStream.Close();
end = DateTime.UtcNow;//////////////////////////////////////
}
#endregion
}
else
{
throw new InvalidDataException("syncronizer type is not valid");
}
return (end - begin).TotalMilliseconds;// return total time to upload in milliseconds
}
示例11: UploadByteArrayToS3Object
public bool UploadByteArrayToS3Object(string s3ObjectName, byte[] input)
{
try
{
MemoryStream ms = new MemoryStream();
ms.Write(input, 0, input.Length);
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.WithKey(s3ObjectName);
request.InputStream = ms;
amazonS3Client.PutObject(request);
return true;
}
catch (Exception e)
{
structuredLog("E", "Exception in UploadFileToS3Object: " + e);
return false;
}
}
示例12: UploadToAmazonService
private void UploadToAmazonService(HttpPostedFileBase file, string filename)
{
string bucketName = System.Configuration.ConfigurationManager.AppSettings["AWSPublicFilesBucket"]; //commute bucket
string publicFile = "Pictures/" + filename; //We have Pictures folder in the bucket
Session["publicFile"] = publicFile;
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.WithKey(publicFile);
request.WithInputStream(file.InputStream);
request.AutoCloseStream = true;
request.CannedACL = S3CannedACL.PublicRead; //Read access for everyone
AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(); //uses AWSAccessKey and AWSSecretKey defined in Web.config
using (S3Response r = client.PutObject(request)) { }
}
示例13: UploadFile
public static string UploadFile(AmazonS3 client, string filepath)
{
//S3_KEY is name of file we want upload
S3_KEY = System.IO.Path.GetFileName(filepath);
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(BUCKET_NAME);
request.WithKey(S3_KEY);
//request.WithInputStream(MemoryStream);
request.WithFilePath(filepath);
client.PutObject(request);
return S3_KEY;
}
示例14: UploadFile
private static void UploadFile(string filePath, string key, string bucket)
{
string AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
string AWSSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"];
using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey))
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucket);
request.WithKey(key);
request.WithFilePath(filePath);
request.CannedACL = S3CannedACL.PublicRead;
client.PutObject(request);
}
}
示例15: CopyImage
private static void CopyImage(object o)
{
UserData u = (UserData)o;
try
{
string imagePath = String.Format("{0}\\L{1:00}\\R{2:x8}\\C{3:x8}.{4}", TileDirectory, u.Level, u.Row, u.Column, ContentType == "image/png" ? "png" : "jpg");
if (File.Exists(imagePath))
{
byte[] file = File.ReadAllBytes(imagePath);
PutObjectRequest putObjectRequest = new PutObjectRequest();
putObjectRequest.WithBucketName(BucketName);
putObjectRequest.WithKey(String.Format("{0}/{1}/{2}/{3}", MapName, u.Level, u.Row, u.Column));
putObjectRequest.WithInputStream(new MemoryStream(file));
putObjectRequest.WithContentType(ContentType);
putObjectRequest.WithCannedACL(S3CannedACL.PublicRead);
_s3Client.PutObject(putObjectRequest);
}
}
catch (Exception ex)
{
}
finally
{
_threadPool.Release();
}
}