【发布时间】:2019-03-19 03:28:39
【问题描述】:
我正在使用 Kotlin 开发一个 Android 应用程序。我正在尝试将文件上传到 AWS S3 存储桶。我可以成功地将文件上传到存储桶。但问题是该文件是作为私有文件上传的。相反,我希望它也被上传并公开。
这是我的代码
private fun uploadPhotoToS3(path : String){
doAsync {
AWSMobileClient.getInstance().initialize(applicationContext).execute()
val s3Client = AmazonS3Client(AWSMobileClient.getInstance().credentialsProvider)
val transferUtility = TransferUtility.builder()
.context(applicationContext)
.awsConfiguration(AWSMobileClient.getInstance().configuration)
.s3Client(s3Client)
.build()
val uploadObserver = transferUtility.upload("public/testing.jpg", File(path))
uploadObserver.setTransferListener(object : TransferListener{
override fun onStateChanged(id: Int, state: TransferState?) {
if(TransferState.COMPLETED == state){
Log.i("UPLOAD_STATE", "COMPLETED")
} else {
Log.i("UPLOAD_STATE", "CHANGED")
}
}
override fun onProgressChanged(id: Int, bytesCurrent: Long, bytesTotal: Long) {
}
override fun onError(id: Int, ex: Exception?) {
Log.i("UPLOAD_ERROR", "Unable to upload file")
}
})
}
}
如何修改它以将文件设置为公开?
【问题讨论】:
标签: android amazon-web-services amazon-s3 kotlin