Skip to content

Instantly share code, notes, and snippets.

@dictav
Created July 5, 2014 06:14
Show Gist options
  • Save dictav/97706011d4ac53a33b57 to your computer and use it in GitHub Desktop.
Save dictav/97706011d4ac53a33b57 to your computer and use it in GitHub Desktop.
/* 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