コード例 #1
0
ファイル: Program.cs プロジェクト: Genbox/SimpleS3
    private static async Task UploadDownloadTransfer(AmazonS3Client client, string bucketName, string objectName)
    {
        Console.WriteLine();
        Console.WriteLine("Using the Transfer API");

        //The Transfer API is an easy-to-use API for building requests.
        IUpload upload = client.CreateUpload(bucketName, objectName)
                         .WithAccessControl(ObjectCannedAcl.PublicReadWrite)
                         .WithCacheControl(CacheControlType.NoCache)
                         .WithEncryption();

        PutObjectResponse putResp = await upload.UploadStringAsync("Hello World!");

        if (putResp.IsSuccess)
        {
            Console.WriteLine("Successfully uploaded the object");

            //Download string
            IDownload download = client.CreateDownload(bucketName, objectName)
                                 .WithRange(0, 5); //Adjust this to return only part of the string

            GetObjectResponse getResp = await download.DownloadAsync();

            if (getResp.IsSuccess)
            {
                Console.WriteLine("Success! The object contained: " + await getResp.Content.AsStringAsync());
            }
            else
            {
                Console.WriteLine("Failed to download the object");
            }
        }
        else
        {
            Console.WriteLine("Failed to upload the object");
        }
    }