private static async Task <OperationResult <string> > Send(string id, ImageIdentity entity, Stream file, ImageType type) { if (file != null) { OperationResult <string> f = checkFile(file); if (!f.Success) { return new OperationResult <string> { Success = false, Result = image_default, Message = f.Message } } ; try { IAmazonS3 client; using (client = AWSClientFactory.CreateAmazonS3Client(_awsAccessKey, _awsSecretKey, RegionEndpoint.GetBySystemName("eu-west-1"))) { string k = null; string guid = null; if (type == ImageType.Album) { guid = Guid.NewGuid().ToString() + f.Result; } k = String.Format("{0}/{1}/{2}/{3}", Enum.GetName(typeof(ImageIdentity), entity), id, Enum.GetName(typeof(ImageType), type), guid == null ? "profile" : guid); var request = new PutObjectRequest() { BucketName = _bucketName, CannedACL = S3CannedACL.PublicRead, Key = k, InputStream = file }; await client.PutObjectAsync(request); return(new OperationResult <string> { Success = true, Result = image_start_path + k, Message = k }); } } catch (Exception ex) { if (entity == ImageIdentity.Users) { return new OperationResult <string> { Success = false, Result = PERSON_IMAGE_DEFAULT, Message = ex.Message } } ; else { return new OperationResult <string> { Success = false, Result = image_default, Message = ex.Message } }; } } else { if (entity == ImageIdentity.Users) { return new OperationResult <string> { Success = false, Result = PERSON_IMAGE_DEFAULT, Message = Messages.DEFAULT_PERSON } } ; else { return new OperationResult <string> { Success = false, Result = image_default, Message = Messages.DEFAULT_AVATAR } }; } }
public static async Task <OperationResult <string> > SendToProvider(string id, ImageIdentity entity, Stream file, ImageType type) { return(await Send(id, entity, file, type)); }