本文整理汇总了C#中AmazonS3.PutObject方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3.PutObject方法的具体用法?C# AmazonS3.PutObject怎么用?C# AmazonS3.PutObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.PutObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
log.Info("Initializing and connecting to AWS...");
s3 = AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USWest1);
indexer = new FileIndexer("Files");
indexer.Index();
s3indexer = new S3Indexer(Settings.Default.BucketName, Settings.Default.FolderName, "S3Tmp", s3);
s3indexer.Index();
log.Info("Comparing local index and remote index.");
var filesToUpload = (from filePair in indexer.FileIndex where !s3indexer.HashedFiles.ContainsKey(filePair.Key) || !s3indexer.HashedFiles[filePair.Key].SequenceEqual(filePair.Value) select filePair.Key).ToList();
var filesToDelete = (from filePair in s3indexer.HashedFiles where !indexer.FileIndex.ContainsKey(filePair.Key) select filePair.Key).ToList();
foreach(var fileDelete in filesToDelete)
{
log.Debug("Deleting file "+fileDelete);
s3.DeleteObject(new DeleteObjectRequest()
{
BucketName = Settings.Default.BucketName,
Key = Settings.Default.FolderName + "/" + fileDelete
});
}
foreach(var fileUpload in filesToUpload)
{
log.Debug("Uploading file "+fileUpload);
s3.PutObject(new PutObjectRequest()
{
BucketName = Settings.Default.BucketName,
Key = Settings.Default.FolderName + "/" + fileUpload,
AutoCloseStream = true,
InputStream = new FileStream("Files/" + fileUpload, FileMode.Open)
});
}
log.Info("Re-indexing files...");
using (MemoryStream stream = new MemoryStream())
{
Serializer.Serialize(stream, indexer.FileIndex);
stream.Position = 0;
s3.PutObject(new PutObjectRequest()
{
BucketName = Settings.Default.BucketName,
Key = Settings.Default.FolderName + "/" + "index.mhash",
InputStream = stream
});
}
log.Info("Done!");
Console.Read();
}
示例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: 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);
}
示例5: 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();
}
示例6: WalkAndUpload
public void WalkAndUpload(string path, string bucket, AmazonS3 client)
{
foreach (var f in Directory.GetFiles(path))
{
var fi = new FileInfo(f);
if (fi.Name.StartsWith("."))
{
continue;
} //ignore ".gitignore"
string fileToPush = f;
string destinationName =
Regex.Split(fileToPush, @"gitCheckout-[\d]*")[1].Replace("\\", "/").TrimStart("/".ToCharArray());
var poR = new PutObjectRequest()
{
BucketName = bucket,
FilePath = fileToPush,
Key = destinationName,
Timeout = -1,
ReadWriteTimeout = 300000,
CannedACL = S3CannedACL.PublicRead
};
var res = client.PutObject(poR);
}
foreach (var d in Directory.GetDirectories(path))
{
var di = new DirectoryInfo(d);
if (di.Name.StartsWith("."))
{
continue;
} //ignore ".git"
WalkAndUpload(d, bucket, client);
}
}
示例7: AddImageToAmazon
private bool AddImageToAmazon(Coupon coupon, HttpPostedFile File, string ext)
{
string count = "";
string keyname = "";
//ext = ".jpg";
//try
//{
string accessKeyID = WebConfigurationManager.AppSettings["AWSAccessKey"];
string secretAccessKeyID = WebConfigurationManager.AppSettings["AWSSecretKey"];
AmazonS3Config s3Config = new AmazonS3Config();
s3Config.UseSecureStringForAwsSecretKey = false;
client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, s3Config);
//count += "1";
ICouponDAO couponDAO = _factoryDAO.GetCouponDAO();
Byte[] imgByte = new byte[0];
//count += "2";
//Create byte Array with file len
imgByte = new Byte[File.ContentLength];
//count += "3";
//force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength);
//count += "4";
//count += ext;
//count += _merchantname;
//count += _couponID.ToString();
//count += File.FileName;
//count += File.FileName.Substring(0, File.FileName.IndexOf("."));
//count += ":";
//count += string.Format("{0}{1}", _couponID.ToString(), ext);
keyname = string.Format("{0}/{1}", _merchantname, File.FileName.Replace(File.FileName.Substring(0, File.FileName.IndexOf(".")), string.Format("{0}{1}", _couponID.ToString(), ext)));
//keyname = string.Format("{0}/{1}", _merchantname, File.FileName.Replace(File.FileName.Substring(0, File.FileName.IndexOf(".")), _couponID.ToString()));
count += keyname;
/*try
{
//first try deleting old item if applicable
DeleteObjectRequest delete_request = new DeleteObjectRequest();
delete_request.WithBucketName("gfck").WithKey(string.Format("coupon/{0}", keyname));
S3Response delete_response = client.DeleteObject(delete_request);
delete_response.Dispose();
}
catch (Exception ex)
{
_log.ErrorFormat("Error trying to delete object from bucket: {0} with exception {1}", keyname, ex.Message);
}*/
string BUCKET_NAME = String.Format("gfck/coupon/{0}", _merchantname);
try
{
//add the bucket just in case not already there.
//PutObjectRequest request1 = new PutObjectRequest();
PutBucketRequest req = new PutBucketRequest();
req.WithBucketName(BUCKET_NAME);
//count += "6";
//request1.WithBucketName("gfck").WithContentType(File.ContentType).WithCannedACL(S3CannedACL.PublicReadWrite).WithKey(BUCKET_NAME);
//S3Response response = client.PutObject(request1);
//response.Dispose();
client.PutBucket(req);
}
catch (Exception ex)
{
_log.DebugFormat("This bucket already exists: {0} with exception {1}", BUCKET_NAME, ex.Message);
}
//count += "5";
PutObjectRequest request = new PutObjectRequest();
//count += "6";
request.WithBucketName("gfck").WithContentType(File.ContentType).WithCannedACL(S3CannedACL.PublicRead).WithKey(string.Format("coupon/{0}", keyname)).WithInputStream(File.InputStream);
count += "here";
S3Response response = client.PutObject(request);
count += "7";
response.Dispose();
count += "8";
if (ext == "")
{
coupon.Image = keyname;
}
else
{
coupon.BottomAdvertisement = keyname;
}
count += "9";
return couponDAO.UpdateCoupon(coupon);
/*}
catch (Exception ex)
{
_log.ErrorFormat("Exception Occurred: Exception={0}", ex.Message);
lblError.Text = String.Format("Error with coupon image. {0} {1} {2}", count, keyName, ex.Message);
lblError.Visible = true;
lblAddSuccessfull.Visible = false;
lblEditSuccessfull.Visible = false;
return false;
}*/
}
示例8: putInS3Bucket
public void putInS3Bucket(resume resume, string txtResults, string[] generatedFiles, string storedFilePath, string generatedFilePath)
{
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
{
string keyName;
S3Response response;
if (resume.hasIMG)
{
var pageNo = 0;
var append = false;
foreach (string fileName in generatedFiles)
{
keyName = "img/" + resume.resumeID.ToString();
keyName = append ? (keyName + "_" + pageNo.ToString()) : keyName;
PutObjectRequest imgRequest = new PutObjectRequest();
imgRequest.WithBucketName("intelrecruiter")
.WithCannedACL(S3CannedACL.PublicRead)
.WithFilePath(fileName)
.WithKey(keyName);
response = client.PutObject(imgRequest);
response.Dispose();
append = true;
pageNo++;
}
}
if (resume.hasTXT)
{
keyName = "txt/" + resume.resumeID.ToString();
PutObjectRequest txtRequest = new PutObjectRequest();
if (resume.hasDOCX)
{
txtRequest.WithBucketName("intelrecruiter")
.WithCannedACL(S3CannedACL.PublicRead)
.WithContentBody(txtResults)
.WithKey(keyName);
}
else
{
txtRequest.WithBucketName("intelrecruiter")
.WithCannedACL(S3CannedACL.PublicRead)
.WithFilePath(generatedFilePath)
.WithKey(keyName);
}
response = client.PutObject(txtRequest);
response.Dispose();
}
if (resume.hasPDF)
{
keyName = "pdf/" + resume.resumeID.ToString();
PutObjectRequest pdfRequest = new PutObjectRequest();
pdfRequest.WithBucketName("intelrecruiter")
.WithCannedACL(S3CannedACL.PublicRead)
.WithFilePath(storedFilePath)
.WithKey(keyName);
response = client.PutObject(pdfRequest);
response.Dispose();
}
if (resume.hasDOCX)
{
keyName = "docx/" + resume.resumeID.ToString();
PutObjectRequest imgRequest = new PutObjectRequest();
imgRequest.WithBucketName("intelrecruiter")
.WithCannedACL(S3CannedACL.PublicRead)
.WithFilePath(storedFilePath)
.WithKey(keyName);
response = client.PutObject(imgRequest);
response.Dispose();
}
}
}
示例9: BackUpToAmazon
private void BackUpToAmazon(AmazonS3 client)
{
try
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(this.BucketName).WithKey(FileLocations.CONFIG_FILENAME)
.WithFilePath(settings.FileLocations.Configuration);
client.PutObject(request);
this.ErrorLabel.ForeColor = Color.Black;
this.ErrorLabel.Text = "The backup was a success!";
}
catch (Exception exception)
{
this.ErrorLabel.ForeColor = Color.Red;
this.ErrorLabel.Text = exception.Message;
}
}
示例10: GetAll
public ActionResult GetAll(int[] resumesToDelete)
{
string executableDir = Server.MapPath("~/executables");
resume resume;
ResumeFiles resumeFileRequest = new ResumeFiles();
var zipName = User.Identity.Name;
var fileName = zipName + ".zip";
string uploadDir = getUploadDir();
Directory.SetCurrentDirectory(uploadDir);
foreach (int resumeID in resumesToDelete)
{
resume = resumeRepository.GetResume(resumeID);
resumeFileRequest.getFilefromS3(resume, zipName);
}
var command = "\"" + executableDir + "\\7za\" a " + fileName + " " + zipName;
ExecuteCommandSync(command);
var fullPath = Path.Combine(uploadDir, fileName);
var folderPath = Path.Combine(uploadDir, zipName);
string contentType = "application/zip";
string keyName = "user_downloads/" + fileName;
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
{
S3Response response;
PutObjectRequest s3request = new PutObjectRequest();
s3request.WithBucketName("intelrecruiter")
.WithCannedACL(S3CannedACL.PublicRead)
.WithFilePath(fullPath)
.WithKey(keyName);
response = client.PutObject(s3request);
response.Dispose();
}
FileInfo newFile = new FileInfo(fullPath);
newFile.Delete();
DirectoryInfo dir = new DirectoryInfo(folderPath);
dir.Delete(true);
return RedirectToAction("List", new { user_download = keyName });
//return File(fullPath, contentType, zipName + ".zip");
/*
FileInfo newFile = new FileInfo(fullPath);
string attachment = string.Format("attachment; filename={0}", fileName);
Response.Clear();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = contentType;
Response.WriteFile(newFile.FullName);
Response.Flush();
newFile.Delete();
DirectoryInfo dir = new DirectoryInfo(folderPath);
dir.Delete(true);
*/
//return RedirectToAction("Index");
}
示例11: 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;
}
示例12: PutObject
private static void PutObject(AmazonS3 s3Client, string bucket, string key)
{
var putObjectRequest = new PutObjectRequest();
putObjectRequest.WithBucketName(bucket)
.WithKey(key)
.WithContentType("text/plain")
.WithContentBody(key);
var objectResponse = s3Client.PutObject(putObjectRequest);
objectResponse.Dispose();
}
示例13: saveSession
private void saveSession(Cookie cookie)
{
string cookieName = cookie.Name;
string cookieValue = cookie.Value;
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
{
PutObjectRequest txtRequest = new PutObjectRequest();
txtRequest.WithBucketName("intelrecruiter")
.WithContentBody(cookieName)
.WithKey(nsbeCookieNameKey);
var response = client.PutObject(txtRequest);
response.Dispose();
txtRequest = new PutObjectRequest();
txtRequest.WithBucketName("intelrecruiter")
.WithContentBody(cookieValue)
.WithKey(nsbeCookieValueKey);
response = client.PutObject(txtRequest);
response.Dispose();
}
nsbeCookie = new Cookie(cookieName, cookieValue, "/");
}