-
Notifications
You must be signed in to change notification settings - Fork 54
Closed
Labels
bugThis issue is a bug.This issue is a bug.documentationThis is a problem with documentation.This is a problem with documentation.p2This is a standard priority issueThis is a standard priority issue
Description
Describe the bug
Hello,
trying to upload file to S3 in Jetpack Compose.
Uri for file i got from PhotoPicker.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected behavior
file uploaded successfully
Current behavior
error: java.lang.IllegalArgumentException: Stream must be replayable to calculate a body hash
Steps to Reproduce
- click button "Open Gallery"
@Composable
fun GalleryScreen() {
var selectedUris by remember {
mutableStateOf<List<Uri>>(emptyList())
}
val multiplePhotoPickerLauncher =
rememberLauncherForActivityResult(contract = ActivityResultContracts.PickMultipleVisualMedia(),
onResult = { uris ->
selectedUris = uris
})
fun onOpenGallery() {
multiplePhotoPickerLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo)
)
}
Row() {
Button(onClick = ::onOpenGallery) {
Text(text = "Open Gallery", color = MaterialTheme.colorScheme.onError)
}
}
}
- prepare additional parameters (bucket, key, metadata) and run fun
upload
private suspend fun upload(bucket: String, key: String, metadata: Map<String, String>, uri: Uri) {
val inputStream = context.contentResolver.openInputStream(uri)
?: throw IllegalArgumentException("Unable to open input stream for URI: ${config.uri}")
try {
inputStream.use { stream ->
S3Client.use { s3 ->
s3.putObject {
bucket = bucket
key = key
metadata = metadata
body = ByteStream.fromInputStream(stream)
}
}
}
} catch (e: Exception) {
Log.d("TAG", "$e")
throw e
}
}
Possible Solution
No response
Context
No response
AWS SDK for Kotlin version
2.0.21
Platform (JVM/JS/Native)
Native
Operating system and version
Ubuntu 20.04.5 LTS
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.documentationThis is a problem with documentation.This is a problem with documentation.p2This is a standard priority issueThis is a standard priority issue