本文整理汇总了C#中Amazon.S3.Transfer.TransferUtilityUploadRequest类的典型用法代码示例。如果您正苦于以下问题:C# TransferUtilityUploadRequest类的具体用法?C# TransferUtilityUploadRequest怎么用?C# TransferUtilityUploadRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransferUtilityUploadRequest类属于Amazon.S3.Transfer命名空间,在下文中一共展示了TransferUtilityUploadRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
示例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 );
}
}
示例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;
}
示例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);
}
}
示例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
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}