Search code examples
c#amazon-web-servicesamazon-s3amazon-cloudfront

CloudfFont GetObjectRequest equivalent to download files from S3


I am revising an application to use a private CloudFront rather than straight from S3.

I have been able to create signed URLs and populate picturboxes as needed.

I am unable to find the CloudFront equivalent of the GetObjectRequest...

for (int num = 1; num < 16; num++)
{

    GetObjectRequest request = new GetObjectRequest
    {
        BucketName = ContainerName,
        Key = tempDownload + @"/" + num + ".jpg"
    };

    try
    {
        //Issue request and remember to dispose of the response
        using (GetObjectResponse response = s3Client.GetObject(request))
        {
          string dest = Path.Combine(newFileFolder, tempDownload + num + ".jpg");
            if (!File.Exists(dest))
            {
                response.WriteResponseStreamToFile(dest);
            }
        }
    }
}

I am trying to download files through Cloudfront onto the application user's hard drive.


Solution

  • CloudFront does not have an equivalent to GetObject. CloudFront is designed to pull data through the HTTP/HTTPS protocols.

    If the files that you want to download to your user's computer are public, then you can simply access them through the CloudFront distributions http/https URL.

    If the files that you want to download is private, then you'll need to setup an Origin Access Identity to Serve Private Content or use Pre-signed URLs through your CloudFront distributions http/https URL.