Created
August 10, 2015 13:32
-
-
Save misodengaku/45ce682dc080a54307ed to your computer and use it in GitHub Desktop.
AWS SDKを使ってさくらのオブジェクトストレージにアクセスするやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const string ACCESS_KEY_ID = "アクセスキーID"; | |
private const string SECRET_ACCESS_KEY = "シークレットアクセスキー"; | |
public static void GetObjectFromObjStorage(string downloadFolder) | |
{ | |
var config = new AmazonS3Config | |
{ | |
ServiceURL = "https://b.sakurastorage.jp/" | |
}; | |
var credentials = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY); | |
IAmazonS3 s3Client = new AmazonS3Client(credentials, config); | |
var objects = s3Client.ListObjects(ACCESS_KEY_ID).S3Objects; | |
// 例として列挙したオブジェクトの中でサイズが最大の物を返す | |
objects.Sort((x, y) => (int)(y.Size - x.Size)); | |
var obj = objects.First(); | |
Console.WriteLine("ETag: " + obj.ETag); | |
Console.WriteLine("Key: " + obj.Key); | |
Console.WriteLine("Size: " + obj.Size); | |
var path = Path.Combine(downloadFolder, Path.GetFileName(obj.Key)); | |
Console.WriteLine("Downloading: " + path); | |
s3Client.DownloadToFilePath(ACCESS_KEY_ID, obj.Key, path, null); | |
Console.WriteLine("complete"); | |
Console.Read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment