本文整理汇总了C#中Amazon.S3.Transfer.TransferUtilityUploadRequest类的典型用法代码示例。如果您正苦于以下问题:C# TransferUtilityUploadRequest类的具体用法?C# TransferUtilityUploadRequest怎么用?C# TransferUtilityUploadRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransferUtilityUploadRequest类属于Amazon.S3.Transfer命名空间,在下文中一共展示了TransferUtilityUploadRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
try
{
TransferUtility fT = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1));
string fileKey = genKey();
TransferUtilityUploadRequest uR = new TransferUtilityUploadRequest
{
BucketName = bucketName,
FilePath = filepath,
CannedACL = S3CannedACL.PublicRead,
Key = fileKey
};
uR.Metadata.Add("Title", "Tiger");
fT.Upload(uR);
Console.WriteLine("File Uploaded. Access \"S3.amazonaws.com/sheltdev/" + fileKey );
Console.ReadKey(false);
}
catch (AmazonS3Exception e)
{
Console.WriteLine(e.Message, e.InnerException);
Console.ReadKey(false);
}
}
开发者ID:hshelton,项目名称:Templates,代码行数:31,代码来源:Program.cs
示例2: Execute
public override IEnumerable<PvcStream> Execute(IEnumerable<PvcStream> inputStreams)
{
var filteredInputStreams = FilterUploadedFiles(inputStreams);
var transfer = new TransferUtility(this.s3client);
foreach (var inputStream in filteredInputStreams)
{
if (inputStream.StreamName == null || inputStream.StreamName.Length == 0)
continue;
var uploadReq = new TransferUtilityUploadRequest();
uploadReq.BucketName = this.bucketName;
uploadReq.InputStream = inputStream;
uploadReq.Key = this.StreamNameToKey(inputStream.StreamName);
uploadReq.Headers.ContentMD5 = this.keyMD5Sums[uploadReq.Key];
uploadReq.Headers.ContentType = MimeMapping.GetMimeMapping(inputStream.StreamName);
if (inputStream.Tags.Contains("gzip"))
{
uploadReq.Headers.ContentEncoding = "gzip";
}
transfer.Upload(uploadReq);
};
return inputStreams;
}
开发者ID:pauljz,项目名称:pvc-s3,代码行数:27,代码来源:PvcS3.cs
示例3: ExecuteS3Task
protected override void ExecuteS3Task()
{
if ( !File.Exists( this.SourceFile ) ) {
throw new BuildException( "source-file does not exist: " + this.SourceFile );
}
using ( TransferUtility transferUtility = new Amazon.S3.Transfer.TransferUtility( this.AccessKey, this.SecretAccessKey ) ) {
TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest {
BucketName = this.BucketName,
FilePath = this.SourceFile,
Key = this.DestinationFile
};
if ( PublicRead ) {
uploadRequest.AddHeader( "x-amz-acl", "public-read" );
}
transferUtility.Upload( uploadRequest );
}
}
开发者ID:robrich,项目名称:NAntTasks,代码行数:18,代码来源:AmazonUploadTask.cs
示例4: Upload
public List<MessageAttachment> Upload(IEnumerable<LocalResource> localResources)
{
List<MessageAttachment> result = new List<MessageAttachment>();
if (null != localResources)
{
foreach (var res in localResources)
{
Guid guid = Guid.NewGuid();
string fileName = Path.GetFileName(res.LocalPath);
string key = guid.ToString() + fileName;
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest()
.WithBucketName(m_BucketName)
.WithFilePath(res.LocalPath)
.WithSubscriber(this.UploadFileProgressCallback)
.WithCannedACL(S3CannedACL.PublicRead)
.WithKey(key);
m_s3transferUtility.Upload(request);
MessageAttachment attachment = new MessageAttachment(new Uri(m_CloudFrontRoot, key), res.Description ?? fileName);
result.Add(attachment);
}
}
return result;
}
开发者ID:victorzzz,项目名称:CraneChat,代码行数:28,代码来源:CraneChatS3Uploader.cs
示例5: UploadFile
public static void UploadFile(System.Tuple<string,string, DateTime> file, string existingBucketName)
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
string accessKeyID = appConfig["AWSAccessKey"];
string secretAccessKey = appConfig["AWSSecretKey"];
try
{
TransferUtility fileTransferUtility = new TransferUtility(accessKeyID, secretAccessKey);
// Use TransferUtilityUploadRequest to configure options.
// In this example we subscribe to an event.
TransferUtilityUploadRequest uploadRequest =
new TransferUtilityUploadRequest()
.WithBucketName(existingBucketName)
.WithFilePath(file.Item1)
.WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256)
.WithKey(file.Item2 + file.Item3.ToString("ddmmyyyymmmmhhss"));
uploadRequest.UploadProgressEvent +=
new EventHandler<UploadProgressArgs>
(uploadRequest_UploadPartProgressEvent);
fileTransferUtility.Upload(uploadRequest);
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
}
catch (AmazonS3Exception e)
{
Console.WriteLine(e.Message + e.InnerException);
}
}
开发者ID:maxrev17,项目名称:docstore,代码行数:34,代码来源:Upload.cs
示例6: SetFileToS3
public void SetFileToS3(string _local_file_path, string _bucket_name, string _sub_directory, string _file_name_S3)
{
// Gelen Değerler :
// _local_file_path : Lokal dosya yolu örn. "d:\filename.zip"
// _bucket_name : S3 teki bucket adı ,Bucket önceden oluşturulmuş olmalıdır.
// _sub_directory : Boş değilse S3 içinde klasör oluşturulur yada varsa içine ekler dosyayı.
// _file_name_S3 : Dosyanın S3 içindeki adı
// IAmazonS3 class'ı oluşturuyoruz ,Benim lokasyonum RegionEndpoint.EUCentral1 onun için onu seçiyorum
// Sizde yüklemek istediğiniz bucket 'ın lokasyonuna göre değiştirmelisiniz.
IAmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.EUCentral1);
// Bir TransferUtility oluşturuyoruz(Türkçesi : Aktarım Programı).
utility = new TransferUtility(client);
// TransferUtilityUploadRequest oluşturuyoruz
request = new TransferUtilityUploadRequest();
if (_sub_directory == "" || _sub_directory == null)
{
request.BucketName = _bucket_name; //Alt klasör girmediysek direk bucket'ın içine atıyor.
}
else
{ // Alt Klasör ve Bucket adı
request.BucketName = _bucket_name + @"/" + _sub_directory;
}
request.Key = _file_name_S3; //Dosyanın S3 teki adı
request.FilePath = _local_file_path; //Lokal Dosya Yolu
}
开发者ID:hizliproje,项目名称:AWSS3Upload,代码行数:28,代码来源:AmazonUploader.cs
示例7: UploadFile
//Pushes file to Amazon S3 with public read permissions
public bool UploadFile(string localFile,string fileName, string contentType)
{
IAmazonS3 client = GetS3Client();
var result = false;
try
{
var request = new TransferUtilityUploadRequest
{
BucketName = _BucketName,
Key = _Prefix+fileName,
FilePath = localFile,
StorageClass = S3StorageClass.Standard,
CannedACL = S3CannedACL.PublicRead,
ContentType = contentType
};
var fileTransferUtility = new TransferUtility(client);
fileTransferUtility.Upload(request);
//PutObjectResponse response2 = client.PutObject(request);
result = true;
}
catch
{
return result;
}
return result;
}
开发者ID:jamesdarragh,项目名称:basic-file-upload,代码行数:30,代码来源:FileService.cs
示例8: UploadFile
public async Task UploadFile(string name,IStorageFile storageFile)
{
var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
var transferUtilityConfig = new TransferUtilityConfig
{
ConcurrentServiceRequests = 5,
MinSizeBeforePartUpload = 20 * MB_SIZE,
};
try
{
using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig))
{
var uploadRequest = new TransferUtilityUploadRequest
{
BucketName = ExistingBucketName,
Key = name,
StorageFile = storageFile,
// Set size of each part for multipart upload to 10 MB
PartSize = 10 * MB_SIZE
};
uploadRequest.UploadProgressEvent += OnUploadProgressEvent;
await transferUtility.UploadAsync(uploadRequest);
}
}
catch (AmazonServiceException ex)
{
// oResponse.OK = false;
// oResponse.Message = "Network Error when connecting to AWS: " + ex.Message;
}
}
开发者ID:prashanthganathe,项目名称:PersonalProjects,代码行数:30,代码来源:AmazonFileBucketTransferUtil.cs
示例9: SendDocument
public void SendDocument(string filePath, string bucket, string destinationPath, string fileNamOnDestinationWithExtension = "index.html", bool isPublic = false)
{
try
{
var transferUtility = new TransferUtility(amazonS3Client);
if (!transferUtility.S3Client.DoesS3BucketExist(bucket))
transferUtility.S3Client.PutBucket(new PutBucketRequest { BucketName = bucket });
var request = new TransferUtilityUploadRequest
{
BucketName = bucket,
Key = string.Format("{0}/{1}", destinationPath, fileNamOnDestinationWithExtension),
FilePath = filePath
};
if (isPublic)
request.Headers["x-amz-acl"] = "public-read";
request.UploadProgressEvent += uploadFileProgressCallback;
transferUtility.Upload(request);
transferUtility.Dispose();
}
catch (Exception ex)
{
throw new Exception("Error send file to S3. " + ex.Message);
}
}
开发者ID:henrylle,项目名称:CodeMetricsExtractor,代码行数:26,代码来源:AmazonS3Integration.cs
示例10: UploadFile
public void UploadFile(string filePath, string toPath)
{
AsyncCallback callback = new AsyncCallback(uploadComplete);
var uploadRequest = new TransferUtilityUploadRequest();
uploadRequest.FilePath = filePath;
uploadRequest.BucketName = bucketName;
uploadRequest.Key = toPath;
transferUtility.BeginUpload(uploadRequest, callback, null);
}
开发者ID:jofrysutanto,项目名称:StormWeb,代码行数:10,代码来源:S3Uploader.cs
示例11: UploadFile
public void UploadFile(string filePath, string toPath)
{
AsyncCallback callback = new AsyncCallback(uploadComplete);
var uploadRequest = new TransferUtilityUploadRequest();
uploadRequest.FilePath = filePath;
uploadRequest.BucketName = bucketName;
uploadRequest.Key = toPath;
//uploadRequest.AddHeader("x-amz-acl", "private");
uploadRequest.UploadProgressEvent += uploadRequest_UploadProgressEvent;
transferUtility.BeginUpload(uploadRequest, callback, toPath);
}
开发者ID:LeoTosti,项目名称:x-drone,代码行数:11,代码来源:S3Uploader.cs
示例12: ExternalPost
public HttpResponseMessage ExternalPost()
{
HttpResponseMessage result = null;
HttpRequest httpRequest = HttpContext.Current.Request;
TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(ConfigService.AwsAccessKeyId
, ConfigService.AwsSecretAccessKey
, Amazon.RegionEndpoint.USWest2));
if (httpRequest.Files.Count > 0)
{
foreach (string file in httpRequest.Files)
{
HttpPostedFile postedFile = httpRequest.Files[file];
string guid = Guid.NewGuid().ToString();
string remoteFilePath = ConfigService.RemoteFilePath + guid + "_" + postedFile.FileName;
TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = ConfigService.BucketName,
//FilePath = filePath,
InputStream = postedFile.InputStream,
//StorageClass = S3StorageClass.ReducedRedundancy,
//PartSize = 6291456, // 6 MB.
Key = remoteFilePath,
//CannedACL = S3CannedACL.PublicRead
};
fileTransferUtility.Upload(fileTransferUtilityRequest);
string paraRemoteFilePath = "/" + remoteFilePath;
ItemResponse<string> response = new ItemResponse<string>();
string userId = UserService.GetCurrentUserId();
ProfileService.UpdatePhotoPath(userId, paraRemoteFilePath);
response.Item = remoteFilePath;
return Request.CreateResponse(HttpStatusCode.Created, response.Item);
}
}
else
{
result = Request.CreateResponse(HttpStatusCode.BadRequest);
}
return result;
}
开发者ID:theklr,项目名称:persona-id,代码行数:51,代码来源:DocsApiController.cs
示例13: Main
static void Main(string[] args)
{
try
{
TransferUtility fileTransferUtility = new
TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1));
// 1. Upload a file, file name is used as the object key name.
fileTransferUtility.Upload(filePath, existingBucketName);
Console.WriteLine("Upload 1 completed");
// 2. Specify object key name explicitly.
fileTransferUtility.Upload(filePath,
existingBucketName, keyName);
Console.WriteLine("Upload 2 completed");
// 3. Upload data from a type of System.IO.Stream.
using (FileStream fileToUpload =
new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
fileTransferUtility.Upload(fileToUpload,
existingBucketName, keyName);
}
Console.WriteLine("Upload 3 completed");
// 4.Specify advanced settings/options.
TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = existingBucketName,
FilePath = filePath,
StorageClass = S3StorageClass.ReducedRedundancy,
PartSize = 5242880, // 5 MB.
Key = keyName,
CannedACL = S3CannedACL.PublicRead
};
fileTransferUtilityRequest.Metadata.Add("param1", "Value1");
fileTransferUtilityRequest.Metadata.Add("param2", "Value2");
fileTransferUtility.Upload(fileTransferUtilityRequest);
Console.WriteLine("Upload 4 completed");
}
catch (AmazonS3Exception s3Exception)
{
Console.WriteLine(s3Exception.Message,
s3Exception.InnerException);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
开发者ID:nimisha84,项目名称:Netezza,代码行数:49,代码来源:Program1.cs
示例14: UploadFileToAmazon
private void UploadFileToAmazon(string bucketName, string localFilePath)
{
try
{
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.BucketName = bucketName;
request.FilePath = localFilePath;
utility.Upload(request);
File.Delete(localFilePath);
}
catch (Exception ex)
{
Helpers.Helpers.LogExceptions(ex.Message);
}
}
开发者ID:AashishUpadhyay,项目名称:MoveFilesToAmazonS3,代码行数:15,代码来源:UploadProcessor.cs
示例15: UploadPhoto
public IPhoto UploadPhoto(Stream stream, string filename, string title, string descriptioSn, string tags)
{
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.InputStream = stream;
request.BucketName = photoBucket;
request.Key = filename;
request.CannedACL = Amazon.S3.Model.S3CannedACL.PublicRead;
TransferUtility transferUtility = new TransferUtility(ConfigurationManager.AppSettings["AWSAccessKey"], ConfigurationManager.AppSettings["AWSSecretKey"]);
transferUtility.Upload(request);
S3Photo photo = new S3Photo();
photo.WebUrl = string.Format("http://s3.amazonaws.com/{0}/{1}", photoBucket, filename);
photo.Title = filename;
return photo;
}
开发者ID:sgwill,项目名称:familyblog,代码行数:17,代码来源:S3PhotoRepository.cs
示例16: UploadFileToS3
private void UploadFileToS3(string filePath,string bucketname)
{
var awsAccessKey = accesskey;
var awsSecretKey = secretkey;
var existingBucketName = bucketname;
var client = Amazon.AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast1);
var uploadRequest = new TransferUtilityUploadRequest
{
FilePath = filePath,
BucketName = existingBucketName,
CannedACL = S3CannedACL.PublicRead
};
var fileTransferUtility = new TransferUtility(client);
fileTransferUtility.UploadAsync(uploadRequest);
}
开发者ID:prashanthganathe,项目名称:PersonalProjects,代码行数:17,代码来源:AmazonFileBucketBackground.cs
示例17: InnerExecute
protected override void InnerExecute(string[] arguments)
{
_writer.WriteLine("Getting upload credentials... ");
_writer.WriteLine();
var uploadCredentials = GetCredentials();
var temporaryFileName = Path.GetTempFileName();
try
{
using (var packageStream = new FileStream(temporaryFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
using (var gzipStream = new GZipStream(packageStream, CompressionMode.Compress, true))
{
var sourceDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
sourceDirectory.ToTar(gzipStream, excludedDirectoryNames: _excludedDirectories.ToArray());
}
using (var s3Client = new AmazonS3Client(uploadCredentials.GetSessionCredentials()))
using (var transferUtility = new TransferUtility(s3Client))
{
var request = new TransferUtilityUploadRequest
{
FilePath = temporaryFileName,
BucketName = uploadCredentials.Bucket,
Key = uploadCredentials.ObjectKey,
Timeout = (int)TimeSpan.FromHours(2).TotalMilliseconds,
};
var progressBar = new MegaByteProgressBar();
request.UploadProgressEvent += (object x, UploadProgressArgs y) => progressBar
.Update("Uploading package", y.TransferredBytes, y.TotalBytes);
transferUtility.Upload(request);
Console.CursorTop++;
_writer.WriteLine();
}
}
finally
{
File.Delete(temporaryFileName);
}
TriggerAppHarborBuild(uploadCredentials);
}
开发者ID:LateralSolutions,项目名称:appharbor-cli,代码行数:45,代码来源:DeployAppCommand.cs
示例18: sendMyFileToS3
public bool sendMyFileToS3(string localFilePath, string bucketName, string subDirectoryInBucket, System.IO.Stream stream, string fileName)
{
// input explained :
// localFilePath = the full local file path e.g. "c:\mydir\mysubdir\myfilename.zip"
// bucketName : the name of the bucket in S3 ,the bucket should be alreadt created
// subDirectoryInBucket : if this string is not empty the file will be uploaded to
// a subdirectory with this name
// fileNameInS3 = the file name in the S3
// create an instance of IAmazonS3 class ,in my case i choose RegionEndpoint.EUWest1
// you can change that to APNortheast1 , APSoutheast1 , APSoutheast2 , CNNorth1
// SAEast1 , USEast1 , USGovCloudWest1 , USWest1 , USWest2 . this choice will not
// store your file in a different cloud storage but (i think) it differ in performance
// depending on your location
IAmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(Amazon.RegionEndpoint.USEast1);
// create a TransferUtility instance passing it the IAmazonS3 created in the first step
TransferUtility utility = new TransferUtility(client);
// making a TransferUtilityUploadRequest instance
var request = new TransferUtilityUploadRequest();
var uploadRequest = new TransferUtilityUploadRequest
{
InputStream = stream,
BucketName = bucketName,
CannedACL = S3CannedACL.PublicRead,
Key = fileName
};
if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
{
request.BucketName = bucketName; //no subdirectory just bucket name
}
else
{ // subdirectory and bucket name
request.BucketName = bucketName + @"/" + subDirectoryInBucket;
}
//request.Key = fileNameInS3; //file name up in S3
request.FilePath = localFilePath;
//local file name
utility.Upload(uploadRequest); //commensing the transfer
return true; //indicate that the file was sent
}
开发者ID:tushargoyal1309,项目名称:EventWeb,代码行数:44,代码来源:AmazonUploader.cs
示例19: SendFileToS3
public bool SendFileToS3(string fileNameInS3)
{
string localFilePath = string.Concat(@"C:\source\MyBookLibrary\MyBookLibrary.Data\Database\", fileNameInS3);
using (_client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.USEast1))
{
TransferUtility utility = new TransferUtility(_client);
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.BucketName = BucketName;
request.Key = fileNameInS3;
request.FilePath = localFilePath;
utility.Upload(request);
Console.Write($"File {fileNameInS3} uploaded.");
return true;
}
}
开发者ID:mercurysn,项目名称:MyBookLibrary,代码行数:20,代码来源:AmazonS3Client.cs
示例20: Upload
public bool Upload(string userID, string fileName, Stream file)
{
bool retval = false;
try
{
TransferUtility fileTransferUtility = new
TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.APSoutheast1));
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.InputStream = file;
request.Key = fileName;
request.BucketName = userID;
request.CannedACL = S3CannedACL.PublicRead;
fileTransferUtility.Upload(request);//file, userID, fileName);
}
catch (AmazonS3Exception amazonS3Exception)
{
throw amazonS3Exception;
}
return retval;
}
开发者ID:EchoPan,项目名称:BreadcrumbAPI,代码行数:22,代码来源:S3Helper.cs
注:本文中的Amazon.S3.Transfer.TransferUtilityUploadRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论