jeudi 30 avril 2015

How do I upload to Amazon S3 using .NET HttpClient WITHOUT using their SDK

How do I upload a file to a bucket on Amazon S3 just using .NET's HttpClient (or WebClient)? It has to be done using "PUT".

I can upload using Amazon's AWS SDK, but I would like to know how to do it without it. I've looked at their documentation for hours and still don't get it.

Any help would be greatly appreciated.

My code using their SDK is:

public static void TestPutObjectAsync() {
        AmazonS3Client client = new AmazonS3Client();
        client.AfterResponseEvent += new ResponseEventHandler(callback);

        PutObjectRequest request = new PutObjectRequest {
            BucketName = BUCKET_NAME,
            Key = "Item1",
            FilePath = FILE_PATH,
        };

        client.PutObjectAsync(request);
}

public static event EventHandler UploadComplete;

public static void callback(object sender, ResponseEventArgs e) {

        if (UploadComplete != null) {
            UploadComplete(sender, e);
        }
}




Aucun commentaire:

Enregistrer un commentaire