To add a file to a folder in a bucket, you need to update the PutObjectRequest key to include the folder before the file name.
public bool UploadFileToS3(string uploadAsFileName, Stream ImageStream, S3CannedACL filePermission, S3StorageClass storageType, string toWhichBucketName) { try { using(client = Amazon.AWSClientFactory.CreateAmazonS3Client(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY)) { PutObjectRequest request = new PutObjectRequest(); request.WithKey( "folder" + "/" + uploadAsFileName ); request.WithInputStream(ImageStream); request.WithBucketName(toWhichBucketName); request.CannedACL = filePermission; request.StorageClass = storageType; client.PutObject(request); } } catch { return false; } return true; }
This is a message that says downloading files to a folder. However, they use TransferUtilityUploadRequest, but should work with PutObjectRequest. Scroll down the page in the corresponding example.
This post shows how to create a folder without downloading a file.
Hope this will be helpful
Edit: Updated code to use used block instead of calling Dispose for best practices.
Brian dishaw
source share