Created
July 5, 2014 06:14
-
-
Save dictav/97706011d4ac53a33b57 to your computer and use it in GitHub Desktop.
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
/* AWS S3 の使い方 */ | |
public fun testAWS() { | |
val accessKey = myActivity?.getString(R.string.aws_access_key) | |
val secretKey = myActivity?.getString(R.string.aws_secret_key) | |
val bucketName = "doya" | |
val s3Client = AmazonS3Client( BasicAWSCredentials(accessKey, secretKey) ) | |
s3Client.setRegion(Region.getRegion(Regions.AP_NORTHEAST_1)) | |
val buckets = s3Client.listBuckets() | |
assertNotNull(buckets) | |
assertTrue( buckets!!.size > 0 ) | |
// upload | |
val fileName = "piyo.txt" | |
val path = myActivity?.getFilesDir() | |
val stream = myActivity?.openFileOutput(fileName, 0) | |
stream?.write("hello, aws".toByteArray()) | |
stream?.close() | |
val file = File(path,fileName) | |
val por = PutObjectRequest("doya",fileName,file) | |
s3Client.putObject(por) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment