/// <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 void SetACL(string fileKey, bool anonymouseReadAccess) { SetACLRequest aclRequest = new SetACLRequest(); aclRequest.Key = fileKey; aclRequest.BucketName = BucketName; S3AccessControlList aclList = new S3AccessControlList(); Owner owner = new Owner(); owner.Id = "oyesil"; owner.DisplayName = ""; aclList.Owner = owner; if (anonymouseReadAccess) { S3Grantee grantPublicRead = new S3Grantee(); grantPublicRead.URI = " http://acs.amazonaws.com/groups/global/AllUsers"; aclList.AddGrant(grantPublicRead, S3Permission.READ); } //Authenticated user read access S3Grantee grantAuthenticatedRead = new S3Grantee(); grantAuthenticatedRead.URI = " http://acs.amazonaws.com/groups/global/AuthenticatedUsers"; aclList.AddGrant(grantAuthenticatedRead, S3Permission.READ); aclRequest.ACL = aclList; Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(ConfigurationLibrary.Config.fileAmazonS3AccessKey, ConfigurationLibrary.Config.fileAmazonS3SecreyKey); SetACLResponse aclResponse = client.SetACL(aclRequest); client.Dispose(); }
public void Dispose() => S3Client?.Dispose();
public void Dispose() { S3Client?.Dispose(); }