Esempio n. 1
0
        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);
        }