public FileService() { Amazon.S3.AmazonS3Config s3Config = new Amazon.S3.AmazonS3Config(); s3Config.ServiceURL = FileService.serviceUrl; this.S3Client = new Amazon.S3.AmazonS3Client(ConfigService.amazonAccessKey, ConfigService.amazonSecretAccessKey, s3Config); }
public FileUploader(string accessKeyId, string secretAccessKey, string serviceUrl) { Amazon.S3.AmazonS3Config s3Config = new Amazon.S3.AmazonS3Config(); s3Config.ServiceURL = serviceUrl; this.S3Client = new Amazon.S3.AmazonS3Client(accessKeyId, secretAccessKey, s3Config); }
public IStorage RetrieveBackend() { if (AmazonS3 != null) { Amazon.S3.AmazonS3Config config = new Amazon.S3.AmazonS3Config() { ServiceURL = AmazonS3.Endpoint, SignatureVersion = AmazonS3.SignatureVersion, Timeout = TimeSpan.FromDays(10) }; return(new S3Storage(AmazonS3.AccessKey, AmazonS3.ApiKey, AmazonS3.Bucket, config) { accessControl = AmazonS3.CannedACL }); } else if (Azure != null) { return(new AzureStorage(Azure.Account, Azure.SasToken, Azure.Container)); } else if (BunnyCDN != null) { return(new BunnyStorage(BunnyCDN.ApiKey, BunnyCDN.StorageZone)); } else if (Filesystem != null) { return(new FilesystemStorage(Filesystem.Directory)); } else { return(new NullStorage()); } }
public async Task <String> SaveFileToAws(FileDto file) { var keyId = _configuration.GetSection("AWS").GetValue <String>("AWSAccessKeyId"); var keySecret = _configuration.GetSection("AWS").GetValue <String>("AWSSecretAccessKey"); var config = new Amazon.S3.AmazonS3Config(); config.RegionEndpoint = Amazon.RegionEndpoint.EUWest3; var client = new Amazon.S3.AmazonS3Client(keyId, keySecret, config); var fileName = $"users-uploads/{Guid.NewGuid().ToString()}-{file.FileName}"; var request = new Amazon.S3.Model.PutObjectRequest { BucketName = "teller-uploads", ContentType = file.ContentType, InputStream = file.ReadStream, Key = fileName, StorageClass = Amazon.S3.S3StorageClass.Standard, CannedACL = Amazon.S3.S3CannedACL.PublicRead, }; var response = await client.PutObjectAsync(request); if (response.HttpStatusCode == HttpStatusCode.OK) { return("https://teller-uploads.s3.amazonaws.com/" + fileName); } else { return(null); } }
public S3Handler() { Amazon.S3.AmazonS3Config s3Config = new Amazon.S3.AmazonS3Config(); // Build Url. s3Config.ServiceURL = ServiceUrl; //Amazon.S3.AmazonS3Client S3Client = null; this.S3Client = new Amazon.S3.AmazonS3Client(AccessKey, SecretKey, s3Config); }
private Amazon.S3.IAmazonS3 CreateS3Client() { var config = new Amazon.S3.AmazonS3Config(); if (!String.IsNullOrEmpty(_config.RegionName)) { config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(_config.RegionName); } return(new Amazon.S3.AmazonS3Client()); }
/// <summary> // /// </summary> /// <param name="siteId"></param> /// <param name="fileName">should be unique id: 234234546.jpg or /// /images/34234234234.pjg /// </param> /// <param name="content"></param> /// <param name="contentType"></param> /// <returns>Returns the URL address of the file...</returns> public string Upload(string filePath, System.IO.Stream fileStream, string contentType) { Amazon.S3.AmazonS3Config config = new Amazon.S3.AmazonS3Config(). WithCommunicationProtocol(Protocol.HTTP); string key = filePath.Replace(BaseURL, ""); Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(ConfigurationLibrary.Config.fileAmazonS3AccessKey, ConfigurationLibrary.Config.fileAmazonS3SecreyKey, config); //System.IO.MemoryStream stream = new System.IO.MemoryStream(content); try { PutObjectRequest request = new PutObjectRequest(); request.WithInputStream(fileStream); request.WithBucketName(BucketName); request.WithKey(key); request.WithCannedACL(S3CannedACL.PublicRead); S3Response response = client.PutObject(request); //response.Dispose(); } catch (Amazon.S3.AmazonS3Exception ex) { if (ex.ErrorCode != null && (ex.ErrorCode.Equals("InvalidAccessKeyId") || ex.ErrorCode.Equals("InvalidSecurity"))) { Console.WriteLine("Please check the provided AWS Credentials."); Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3"); } else { Console.WriteLine("An error occurred with the message '{0}' when writing an object", ex.Message); } } client.Dispose(); //SetACL(fileName, true); string fileUrl = BaseURL + key; return(fileUrl); }
public ActionResult Edit(TimelineEvent timelineEvent) { try { var file = Request.Files["file"]; if (file != null && file.FileName.EndsWith(".png") || file.FileName.EndsWith(".jpg")) { var fullPath = Server.MapPath("/" + file.FileName); file.SaveAs(fullPath); var config = new Amazon.S3.AmazonS3Config { MaxErrorRetry = 0 }; var client = new Amazon.S3.AmazonS3Client("AKIAJTSDXO36LAHQEOJA", "+HW/vJzJ+XApMYhBzVtAYElxiEZIVw24NXTYBtiG", config); var req = new Amazon.S3.Model.PutObjectRequest { BucketName = "10years-dawitisaak", FilePath = fullPath }; var res = client.PutObject(req); timelineEvent.Image = res.AmazonId2; } // TODO: Add update logic here timelineEvent = timelineService.Save(timelineEvent); return RedirectToAction("Details", new { id = timelineEvent.Id }); } catch(Exception ex) { throw ex; ModelState.AddModelError("Could not Edit", ex); return View(timelineEvent); } }