public async Task <StorageClientDownloadResponse> Download(StorageClientDownloadRequest request) { AmazonS3Client s3Client = new AmazonS3Client(accesskey, secretkey, bucketRegion); TransferUtility fileTransferUtility = new TransferUtility(s3Client); try { string tempFileLocation = Path.GetTempFileName(); TransferUtilityDownloadRequest fileTransferUtilityRequest = new TransferUtilityDownloadRequest { BucketName = bucketName, FilePath = tempFileLocation, Key = request.DownloadPath }; await fileTransferUtility.DownloadAsync(fileTransferUtilityRequest); fileTransferUtility.Dispose(); byte[] fileData = await File.ReadAllBytesAsync(tempFileLocation); //try clean up try { File.Delete(tempFileLocation); } catch { //not the worse if it fails... } return(new StorageClientDownloadResponse { FilePath = request.DownloadPath, FileData = fileData }); } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { return(new StorageClientDownloadResponse { Success = false, Message = "Check the provided AWS Credentials." }); } else { return(new StorageClientDownloadResponse { Success = false, Message = $"Error occurred: {amazonS3Exception.Message}" }); } } }
public Task <StorageClientDownloadResponse> Download(StorageClientDownloadRequest request) { throw new System.NotImplementedException(); }