I'm trying to upload files (Images & Video) to an AWS CloudFront distribution, that points to an s3 bucket.
Currently, I can use the HttpClient to GET and PUT files using signed URLs generated via the CloudFront SDK.
using (HttpClient client = new HttpClient())
using (var stream = File.OpenRead(filepath))
using (HttpResponseMessage response = await client.PutAsync(url, new StreamContent(stream)))
{
response.EnsureSuccessStatusCode();
}
I originally tried a POST, but this didn't work at all (it timed out after 30 seconds) and I found from this SO Answer that I need to add client.DefaultRequestHeaders.Add("x-amz-acl", "bucket-owner-full-control");
to give my object ACL access permissions so the bucket owner can access via the console.
I know I can upload to S3 using the AWS S3 SDK and I could enable transfer acceleration, though the AWS FAQ states that CloudFront is a better choice when uploading smaller files or datasets (< 1GB).
I've found the CloudFront documentation vague, wrong or non-existant for anything other than the initial setup of the CloudFront distribution.
Is the above method the correct way to upload any files to S3 via CloudFront, or is there an optimised, more robust way (e.g. multi-part uploads, so larger files can be resumed) - I want to optimise this for uploading Video, so if answers could focus on this it would be appreciated.