diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 16116b9..24902b8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -101,6 +101,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/kr/ac/duksung/rebit/CreateReviewActivity.kt b/app/src/main/java/kr/ac/duksung/rebit/CreateReviewActivity.kt index 8c1d433..315a152 100644 --- a/app/src/main/java/kr/ac/duksung/rebit/CreateReviewActivity.kt +++ b/app/src/main/java/kr/ac/duksung/rebit/CreateReviewActivity.kt @@ -18,6 +18,9 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.amazonaws.auth.BasicAWSCredentials +import com.amazonaws.services.s3.AmazonS3Client +import com.amazonaws.services.s3.model.PutObjectRequest import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.unity3d.player.e @@ -54,10 +57,21 @@ class CreateReviewActivity() : AppCompatActivity() { private lateinit var imageResult: ActivityResultLauncher + fun uploadFileToS3(file: File, bucketName: String, accessKey: String, secretKey: String) { + val credentials = BasicAWSCredentials(accessKey, secretKey) + val s3Client = AmazonS3Client(credentials) + + val putObjectRequest = PutObjectRequest(bucketName, file.name, file) + val putObject = s3Client.putObject(putObjectRequest) + Log.d("S3_CHECK: " , putObject.toString()) + } + + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_create_review) + val ratingBar = findViewById(R.id.ratingBar) val reviewEditText = findViewById(R.id.reviewEditText) val storeNameTextArea = findViewById(R.id.storeNameTextArea) @@ -91,12 +105,16 @@ class CreateReviewActivity() : AppCompatActivity() { imageUri?.let { //서버 업로드를 위해 파일 형태로 변환한다 var imageFile = File(getRealPathFromURI(it)) + //이미지를 불러온다 Glide.with(this) .load(imageUri) .fitCenter() .apply(RequestOptions().override(500, 500)) .into(ReviewImageArea) + + val uploadTask = UploadTask(imageFile, BuildConfig.bucketName, BuildConfig.accessKey, BuildConfig.secretKey) + uploadTask.execute() } // 여기서 할당 photo = imageUri.toString() diff --git a/app/src/main/java/kr/ac/duksung/rebit/UploadTask.kt b/app/src/main/java/kr/ac/duksung/rebit/UploadTask.kt new file mode 100644 index 0000000..467779e --- /dev/null +++ b/app/src/main/java/kr/ac/duksung/rebit/UploadTask.kt @@ -0,0 +1,24 @@ +package kr.ac.duksung.rebit + +import android.os.AsyncTask +import android.util.Log +import com.amazonaws.auth.BasicAWSCredentials +import com.amazonaws.services.s3.AmazonS3Client +import com.amazonaws.services.s3.model.PutObjectRequest +import java.io.File + +class UploadTask(private val file: File, private val bucketName: String, private val accessKey: String, private val secretKey: String) : AsyncTask() { + + override fun doInBackground(vararg params: Void): String { + val credentials = BasicAWSCredentials(accessKey, secretKey) + val s3Client = AmazonS3Client(credentials) + + val putObjectRequest = PutObjectRequest(bucketName, file.name, file) + val putObject = s3Client.putObject(putObjectRequest) + return putObject.toString() + } + + override fun onPostExecute(result: String) { + Log.d("S3_CHECK: ", result) + } +}