本文整理汇总了C#中Amazon.S3.Model.PutObjectRequest.WithFilePath方法的典型用法代码示例。如果您正苦于以下问题:C# PutObjectRequest.WithFilePath方法的具体用法?C# PutObjectRequest.WithFilePath怎么用?C# PutObjectRequest.WithFilePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.Model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.WithFilePath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write_File_To_S3
public static bool Write_File_To_S3(String path, String key_name)
{
DateTime before = DateTime.Now;
try
{
// simple object put
PutObjectRequest request = new PutObjectRequest();
request.WithFilePath(path)
.WithBucketName(bucketName)
.WithKey(key_name);
S3Response response = s3_client.PutObject(request);
response.Dispose();
}
catch (Exception e)
{
Console.WriteLine("Exception n Write_File_To_S3(String path=" + path + ", String key_name=" + key_name + "). e.Message="+e.Message);
Console.WriteLine("Write_File_To_S3(String path=" + path + ", String key_name=" + key_name + ") failed!!!");
return false;
}
TimeSpan uploadTime = DateTime.Now - before;
Console.WriteLine("Uploading " + path + " into S3 Bucket=" + bucketName + " , key=" + key_name + " took " + uploadTime.TotalMilliseconds.ToString() + " milliseconds");
return true;
}
示例2: 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;
}
示例3: InsertObject
public string InsertObject(string filePath, string keyName)
{
var putRequest = new PutObjectRequest();
putRequest.WithFilePath(filePath)
.WithBucketName(BucketName)
.WithKey(keyName)
.WithCannedACL(S3CannedACL.PublicRead);
using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client(AccessKeyId, SecretAccessKeyId))
{
S3Response putResponse = client.PutObject(putRequest);
return string.Format("http://s3.amazonaws.com/{0}/{1}", BucketName, keyName);
}
}
示例4: 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;
}
}
示例5: WriteLogFile
public static bool WriteLogFile(string uploadFilePath, string credentialFilePath)
{
Type t = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
LogEvents.S3UploadStarted(t, uploadFilePath);
try
{
if(ReadS3Credentials(credentialFilePath) == false)
{
LogEvents.S3NoCredentials(t);
return false;
}
AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(_accessKeyId, _secretAccessKey);
PutObjectRequest request = new PutObjectRequest();
string fileName = System.IO.Path.GetFileName(uploadFilePath);
request.WithFilePath(uploadFilePath).WithBucketName(_bucketName).WithKey(fileName);
S3Response responseWithMetadata = client.PutObject(request);
return true;
}
catch (AmazonS3Exception amazonS3Exception)
{
LogEvents.S3Error(t, amazonS3Exception);
return false;
}
}
示例6: 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);
}
}
示例7: 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));
//.........这里部分代码省略.........
示例8: PublishFile
/// <summary>
/// Publishes a file to Amazon S3.
/// </summary>
/// <param name="filePath">The path of the file to publish.</param>
private void PublishFile(string filePath)
{
NameValueCollection headers = new NameValueCollection();
string contentType = MimeType.FromCommon(filePath).ContentType;
string objectKey = this.ObjectKey(filePath);
if (this.OverwriteExisting || !this.ObjectExists(objectKey))
{
PutObjectRequest request = new PutObjectRequest()
.WithBucketName(this.BucketName)
.WithCannedACL(S3CannedACL.PublicRead)
.WithContentType(contentType)
.WithKey(objectKey)
.WithTimeout(this.Timeout);
bool gzip = false;
string tempPath = null;
if (contentType.StartsWith("text", StringComparison.OrdinalIgnoreCase))
{
gzip = true;
tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetRandomFileName());
using (FileStream fs = File.OpenRead(filePath))
{
using (FileStream temp = File.Create(tempPath))
{
using (GZipStream gz = new GZipStream(temp, CompressionMode.Compress))
{
byte[] buffer = new byte[4096];
int count;
while (0 < (count = fs.Read(buffer, 0, buffer.Length)))
{
gz.Write(buffer, 0, count);
}
}
}
}
headers["Content-Encoding"] = "gzip";
request = request.WithFilePath(tempPath);
}
else
{
request = request.WithFilePath(filePath);
}
request.AddHeaders(headers);
using (PutObjectResponse response = this.Client().PutObject(request))
{
}
if (!String.IsNullOrEmpty(tempPath) && File.Exists(tempPath))
{
File.Delete(tempPath);
}
this.PublisherDelegate.OnFilePublished(filePath, objectKey, gzip);
}
else
{
this.PublisherDelegate.OnFileSkipped(filePath, objectKey);
}
}
示例9: 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;
}
示例10: objectSerial
public static void objectSerial(String filePath)
{
System.Console.WriteLine("\nhello,object!!");
NameValueCollection appConfig = ConfigurationManager.AppSettings;
AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
String bucketName = "chttest3";
String objectName = "hello";
//String filePath = "D:\\Visual Studio Project\\TestNetSDK\\TestNetSDK\\pic.jpg";
//PutBucket
System.Console.WriteLine("PutBucket: {0}\n",bucketName);
PutBucketResponse response = s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));
//PutObject
System.Console.WriteLine("PutObject!\n");
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);
//HeadObject
System.Console.WriteLine("HeadObject!\n");
GetObjectMetadataResponse HeadResult = s3Client.GetObjectMetadata(new GetObjectMetadataRequest().WithBucketName(bucketName).WithKey(objectName));
System.Console.WriteLine("HeadObject: (1)ContentLength: {0} (2)ETag: {1}\n", HeadResult.ContentLength,HeadResult.ETag);
//GetObject
System.Console.WriteLine("GetObject!\n");
GetObjectResponse GetResult = s3Client.GetObject(new GetObjectRequest().WithBucketName(bucketName).WithKey(objectName).WithByteRange(1,15));
Stream responseStream = GetResult.ResponseStream;
StreamReader reader = new StreamReader(responseStream);
System.Console.WriteLine("Get Object Content:\n {0}\n", reader.ReadToEnd());
System.Console.WriteLine("Get Object ETag:\n {0}\n", GetResult.ETag);
//CopyObject
CopyObjectResponse CopyResult = s3Client.CopyObject(new CopyObjectRequest().WithSourceBucket(bucketName).WithSourceKey(objectName).WithDestinationBucket(bucketName).WithDestinationKey("hihi"));
System.Console.WriteLine("CopyObject: ETag: {0} \n",CopyResult.ETag);
//DeleteObject
System.Console.WriteLine("Delete Object!\n");
s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey(objectName));
s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey("hihi")); //copied object
//==============================jerry add ==============================
System.Console.WriteLine("Jerry Add!\n");
String objectName2 = "hello2";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("A", "ABC");
System.Console.WriteLine("PutObject!\n");
PutObjectRequest request2 = new PutObjectRequest();
request2.WithBucketName(bucketName);
request2.WithKey(objectName2);
request2.WithAutoCloseStream(true);
request2.WithCannedACL(S3CannedACL.BucketOwnerFullControl);
request2.WithContentBody("test");
request2.WithContentType("test/xml");
request2.WithGenerateChecksum(true);
request2.WithMD5Digest("CY9rzUYh03PK3k6DJie09g==");
request2.WithMetaData(nvc);
request2.WithWebsiteRedirectLocation("http://hicloud.hinet.net/");
PutObjectResponse PutResult2 = s3Client.PutObject(request2);
System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult2.ETag);
System.Console.WriteLine("GetObject!\n");
GetObjectRequest request3 = new GetObjectRequest();
request3.WithBucketName(bucketName);
request3.WithKey(objectName2);
request3.WithByteRange(1, 2);
DateTime datetime = DateTime.UtcNow;
// 似乎不支援 datetime
request3.WithModifiedSinceDate(datetime.AddHours(-1));
request3.WithUnmodifiedSinceDate(datetime.AddHours(1));
request3.WithETagToMatch(PutResult2.ETag);
request3.WithETagToNotMatch("notMatch");
GetObjectResponse GetResult2 = s3Client.GetObject(request3);
Stream responseStream2 = GetResult2.ResponseStream;
StreamReader reader2 = new StreamReader(responseStream2);
System.Console.WriteLine("Get Object Content(es):\n {0}\n", reader2.ReadToEnd());
System.Console.WriteLine("Get Object ETag:\n {0}\n", GetResult2.ETag);
System.Console.WriteLine("HeadObject!\n");
GetObjectMetadataRequest request4 = new GetObjectMetadataRequest();
request4.WithBucketName(bucketName);
request4.WithKey(objectName2);
DateTime datetime2 = DateTime.UtcNow;
// 似乎不支援 datetime
request4.WithModifiedSinceDate(datetime2.AddHours(-1));
request4.WithUnmodifiedSinceDate(datetime2.AddHours(1));
request4.WithETagToMatch(PutResult2.ETag);
request4.WithETagToNotMatch("notMatch");
GetObjectMetadataResponse HeadResult2 = s3Client.GetObjectMetadata(request4);
System.Console.WriteLine("HeadObject: (1)ContentLength: {0} (2)ETag: {1}\n", HeadResult2.ContentLength, HeadResult2.ETag);
CopyObjectRequest request5 = new CopyObjectRequest();
//.........这里部分代码省略.........
示例11: Save
public String Save(DirectoryEnum denum, String localFilename)
{
String directory = getDirectory(denum);
if (_storageMode == StorageMode.S3)
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("FaceSpace");
String s3path = directory + _directorySeparator + Path.GetFileName(localFilename);
request.WithKey(s3path);
request.WithFilePath(localFilename);
request.AutoCloseStream = true;
request.CannedACL = S3CannedACL.PublicRead;
AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(_accessKey, _secretKey, RegionEndpoint.USEast1);
//var client = Amazon.AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USEast1);
using (S3Response r = client.PutObject(request)) { }
return "https://s3.amazonaws.com/FaceSpace/" + s3path;
}
else
{
String dest = _localPath + "\\" + directory + _directorySeparator + Path.GetFileName(localFilename);
System.IO.File.Copy(localFilename, dest, true);
return _virtualDirectory + "\\" + directory + _directorySeparator + Path.GetFileName(localFilename);
}
}