Question:
I’m using AWS SDK for .NET and I was looking for a method to let user upload directly to a s3 storage.
I’ve come across two different ways offedered by aws:
Browser based upload: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html
and presigned urls: https://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjectPreSignedURLDotNetSDK.html
It seems presigned url is ‘easier’ since a method is already present within aws sdk to generate a url to pass to client, to let him PUT object directly to the bucket (and it seems also painless compared to browser upload, since it doesn’t require all the keys browser upload wants in the post form).
But I was wondering why there are actually two different methods. What are PRO and CONS of each one?
Answer:
It totally comes down to the point, whether you want to use the REST API or the AWS SDKs to interact with S3.
In both cases, you need to prove(authenticate/Sign-Request) your identity unless bucket is public.
a) If you are going with REST APIs, to prove identity, you need sign your request using ‘ AWS Signature version 4 ‘ (deprecated ver 2 is also there), which includes three methods (one you have listed)
- Authenticating Requests: Using the Authorization Header (AWS Signature Version 4)
- Authenticating Requests: Using Query Parameters (AWS Signature Version 4)
- Authenticating Requests: Browser-Based Uploads Using POST (AWS Signature Version 4)
b) If you are going to use AWS SDKs, you should let SDK do the signing ceremony(process). So the choice is straightforward to use SDK to sign the request
(Part of the question) It seems also painless compared to browser upload since it doesn’t require all the keys browser upload wants in the post form<
For below code, s3Client
already has got your creds whether from AWS-CLI-Profile(if running local/laptop), IAM Role(in case of EC2, lambda, etc)
1 2 |
string url = s3Client.GetPreSignedURL(request); |