This file contains 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
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 = { |
This file contains 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
fun getUploadedFileUrl( | |
fileKey: String | |
): String { | |
var url: URL? = null | |
Amplify.Storage.getUrl( | |
fileKey, | |
{ | |
Log.i("Amplify", "Url Successfully generated: ${it.url}") | |
url = it.url | |
}, |
This file contains 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
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) } | |
) |
This file contains 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
//the upload method | |
fun uploadPhoto( | |
context: Context, | |
imageUri: Uri, | |
contentResolver: ContentResolver, | |
fileKey: String | |
): String { | |
var url = "" | |
val stream = contentResolver.openInputStream(imageUri) | |
if (stream != null) { |
This file contains 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
class MainActivity : ComponentActivity() { | |
//this is a Jetpack compose code | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
Theme { | |
configureAmplify(this) | |
MainAppScreen() | |
} | |
} |
This file contains 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
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) | |
} |
This file contains 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
? 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.` |
This file contains 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
? 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 |
This file contains 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
amplify init |
This file contains 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
amplify configure |