public void RenameFolder(string oldPath, string newPath) { oldPath = CleanPath(oldPath); newPath = CleanPath(newPath); var oldDir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, oldPath); var newDir = new S3DirectoryInfo(_client, _amazonS3StorageConfiguration.AWSFileBucket, newPath); oldDir.MoveTo(newDir); }
public void RenameFolder(string path, string newPath) { if (!IsFolderExits(path)) { throw new InvalidOperationException("Directory " + path + "does not exist"); } if (IsFolderExits(newPath)) { throw new InvalidOperationException("Directory " + newPath + " already exists"); } var di = new S3DirectoryInfo(_amazonS3, _bucketName, path); var newDi = new S3DirectoryInfo(_amazonS3, _bucketName, newPath); di.MoveTo(newDi); }
public OperationResponse MoveFolder(string sourceBucket, string sourceKey, string destinationBucket, string destinationKey, bool overwriteDestinationFolder, RegionEndpoint region) { var operationResponse = new OperationResponse(); try { if (overwriteDestinationFolder) { operationResponse = this.DeleteFolder(destinationBucket, destinationKey, region); } this.IsValid(_awsAccessKey, _awsSecretAccessKey, sourceBucket, sourceKey, destinationBucket, destinationKey, region); using (var client = new AmazonS3Client(_awsAccessKey, _awsSecretAccessKey, region)) { S3DirectoryInfo origin = new S3DirectoryInfo(client, sourceBucket, sourceKey.ToSlashesFileSystem()); S3DirectoryInfo target = new S3DirectoryInfo(client, destinationBucket, destinationKey.ToSlashesFileSystem()); target.Create(); operationResponse.S3DirectoryInfo = origin.MoveTo(target); } operationResponse.StatusCode = System.Net.HttpStatusCode.OK; } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { operationResponse.Message = "Please check the provided AWS Credentials. If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3"; operationResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError; } else { operationResponse.Message = amazonS3Exception.Message; operationResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError; } } catch (Exception oException) { operationResponse.Message = oException.Message; operationResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError; } return(operationResponse); }