0

I am using ASP.NET Core and AWSSDK.S3 nuget package.

I am able to upload file by providing accessKeyID, secretKey, bucketName and region

Like this:

var credentials = new BasicAWSCredentials(accessKeyID, secretKey);

   using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
   {
       var request = new PutObjectRequest
       {
             AutoCloseStream = true,
             BucketName = bucketName,
             InputStream = storageStream,
             Key = fileName
       }
   }

But I am given only an URL to upload file

11.11.11.111:/aa-bb-cc-dd-useast1

How to upload file through the URL? I am new to AWS,I will be grateful to get some help.

4
  • Look like asked same question.. Commented Dec 18, 2019 at 8:37
  • @TuanVA Not exactly, I will upload the file from application itself. I need to know how ti use AWS VPC enpoint for S3 Commented Dec 18, 2019 at 8:41
  • Just enable S3 Endpoint, then network with do the rest. Commented Dec 18, 2019 at 8:43
  • I need to find some code in .net core. The endpoint is enabled. I am not sure how to write the code using the AWSSDK.S3 nuget package Commented Dec 18, 2019 at 8:44

1 Answer 1

1
using Amazon.S3;
using Amazon.S3.Transfer;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Amazon.DocSamples.S3
{
    class UploadFileMPUHighLevelAPITest
    {
       private const string bucketName = "*** provide bucket name ***";
       private const string filePath = "*** provide the full path name of the file to upload ***";
        // Specify your bucket region (an example region is shown).
        private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
        private static IAmazonS3 s3Client;

        public static void Main()
        {
            s3Client = new AmazonS3Client(bucketRegion);
            UploadFileAsync().Wait();
        }

        private static async Task UploadFileAsync()
        {
            try
            {
                var fileTransferUtility =
                    new TransferUtility(s3Client);  
                // Option 1. Upload a file. The file name is used as the object key name.
               await fileTransferUtility.UploadAsync(filePath, bucketName);
               Console.WriteLine("Upload 1 completed");

             }
         }
      }
    }

https://docs.aws.amazon.com/AmazonS3/latest/dev/HLuploadFileDotNet.html

You can use the provided access point in place of the bucket name.

https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/S3/TPutObjectRequest.html

Sign up to request clarification or add additional context in comments.

5 Comments

If you are given a url, then u guess thats the access point to the bucket. Replace the bucketname with the access point.
Ok. Thank you. I will try and let you know
Hi, I am getting error: "Unable to get IAM security credentials from EC2 Instance Metadata Service.'" I think if i am given access this should work. ANy thoughts?
Yes. The app should have credentials of the aws account in the web config or in the code
Thanks. I am new in AWS, have very little knowledge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.