Skip to content

Instantly share code, notes, and snippets.

View RaheemJnr's full-sized avatar
🎯
Focusing

Raheem Jnr RaheemJnr

🎯
Focusing
View GitHub Profile
@RaheemJnr
RaheemJnr / BasicTextField.kt
Last active December 27, 2022 07:30
a simple basic text field
var input by remember { mutableStateOf("") }
BasicTextField(
modifier = Modifier
.wrapContentSize()
.padding(horizontal = 12.dp)
.border(width = 1.5.dp, color = Color.Black, RoundedCornerShape(12.dp)),
value = input,
textStyle = MaterialTheme.typography.h4,
onValueChange = {
fun getUploadedFileUrl(
fileKey: String
): String {
var url: URL? = null
Amplify.Storage.getUrl(
fileKey,
{
Log.i("Amplify", "Url Successfully generated: ${it.url}")
url = it.url
},
val file = File("${applicationContext.filesDir}/download.txt")
Amplify.Storage.downloadFile("ExampleKey", file,
{ Log.i("MyAmplifyApp", "Successfully downloaded: ${it.file.name}") },
{ Log.e("MyAmplifyApp", "Download Failure", it) }
)
//the upload method
fun uploadPhoto(
context: Context,
imageUri: Uri,
contentResolver: ContentResolver,
fileKey: String
): String {
var url = ""
val stream = contentResolver.openInputStream(imageUri)
if (stream != null) {
class MainActivity : ComponentActivity() {
//this is a Jetpack compose code
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Theme {
configureAmplify(this)
MainAppScreen()
}
}
fun configureAmplify(context: Context) {
try {
Amplify.addPlugin(AWSCognitoAuthPlugin())
Amplify.addPlugin(AWSS3StoragePlugin())
Amplify.configure(context)
Log.i("Amplify Log", "Initialized Amplify")
} catch (error: AmplifyException) {
Log.e("Amplify Log", "Could not initialize Amplify", error)
}
? Please select from one of the below mentioned services:
`Content (Images, audio, video, etc.)`
? You need to add auth (Amazon Cognito) to your project in order to add storage for user files. Do you want to add auth now?
`Yes`
? Do you want to use the default authentication and security configuration?
`Default configuration`
? How do you want users to be able to sign in?
`Username`
? Do you want to configure advanced settings?
`No, I am done.`
? Enter a name for the project uploadtos3android
The following configuration will be applied:
Project information
| Name: uploadtos3android
| Environment: dev
| Default editor: Android Studio
| App type: android
| Res directory: app/src/main/res
amplify init
amplify configure