public async Task CreateFile(IStorageDirectory directory, string name, Stream file) { AWSStorageDirectory s3Directory = (directory as AWSStorageDirectory); if (s3Directory != null) { S3FileInfo s3File = s3Directory.DirectoryInfo.GetFile(name); if (!s3File.Exists) { string fullName = s3Directory.DirectoryInfo.GetDirectoryPath() + name; var request = new PutObjectRequest { BucketName = s3File.Directory.Bucket.Name, Key = fullName, InputStream = file }; PutObjectResponse response = await Task.Factory.FromAsync( _client.BeginPutObject(request, null, null), (result) => _client.EndPutObject(result)); } else { throw new ArgumentException("File already exists"); } } else { throw new ArgumentException("directory parameter must be created through the AWS library"); } }
public async Task <IStorageDirectory> CreateDirectory(IStorageDirectory parent, string name) { AWSStorageDirectory newDirectory = null; // Verify the directory name ends with a / (specifies its a directory in AWS) S3DirectoryInfo parentDirectory; if (parent == null) { parentDirectory = _rootDirectory; } else { parentDirectory = ((AWSStorageDirectory)parent).DirectoryInfo; } S3DirectoryInfo directory = parentDirectory.GetDirectory(name); // Get the full path of the directory, without the bucket name at the beginning, and the tracking :/ string fullPath = directory.GetDirectoryPath(); // Check if directory already exists if (!directory.Exists) { var request = new PutObjectRequest { BucketName = _rootDirectory.Name, Key = fullPath, InputStream = new MemoryStream() }; PutObjectResponse response = await Task.Factory.FromAsync( _client.BeginPutObject(request, null, null), (result) => _client.EndPutObject(result)); newDirectory = directory.ToStorageDirectory(); } else { throw new Exception("Directory already exists"); } return(newDirectory); }