Gun
Gun

Reputation: 521

Is it possible to request AWS S3 to download a file?

For the moment I use a C# app to download a picture from a known URL and upload it on AWS S3 server.

using (WebClient c = new WebClient())
{
    var data = c.DownloadData(ad.PhotoUrl);
    var s3 = new AmazonS3Client(RegionEndpoint.EUWest1);
    using (var memoryStream = new MemoryStream(data))
    {
        using (var yourBitmap = new Bitmap(memoryStream))
        {
            yourBitmap.Save(memoryStream, ImageFormat.Jpeg);
            var titledRequest = new PutObjectRequest
            {
                CannedACL = S3CannedACL.PublicRead,
                InputStream = memoryStream,
                BucketName = myBucket,
                Key = keyName
            };
            s3.PutObject(titledRequest);
        }
    }
}

It works fine but I would like to avoid this method, I have a constant huge image flow to store / delete so it would kill my bandwidth. Is it possible to bypass the "download" part ? I mean, can I ask to AWS S3 server to download the image located at ad.PhotoUrl on his own? C# is not required for the "distant request". I just like to know if it's possible so I could dig a little to find a solution.

To make it simple, I just to say to AWS S3 : Hey can you download this image and store it for me ? Instead of : Hey, here is the image I just downloaded, can you store it?

Upvotes: 1

Views: 1815

Answers (1)

Bram
Bram

Reputation: 4532

S3 cannot do this (because it really only does file-storage), but you can solve this by using a Lambda-function that initiates the download and pushes the file into S3. The Lambda-function in turn can be invoked via the AWS SDK or an API-gateway HTTP request.

Upvotes: 3

Related Questions